Nanomagnets, namely arrays of a few exchange-coupled atomic magnetic moments, possess a rich variety of magnetic properties and are explored as constituents of nanospintronics technologies. They have been realized as magnetic clusters or molecular nanomagnets. Individual nanomagnets, built from magnetic atoms adsorbed onto a nonmagnetic surface (adatoms) coupled by Ruderman–Kittel–Kasuya–Yosida exchange, exhibit a high level of versatility resulting from distance-dependent interactions. Here, we combine spin-resolved scanning tunnelling microscopy, atom manipulation and simulations to tailor nanomagnets ranging from linear chains to complex two-dimensional arrays and perform magnetometry in an atom-by-atom fashion. Distinct ground states of each chain, depending on even or odd numbers of constituent atoms, and magnetic frustration within the arrays have been observed directly. Our work demonstrates real-space access to the magnetic states of tailored nanostructures providing an approach to tackling open fundamental questions in magnetism.