The original magnetic properties of nanometre-sized particles are due to the distinct contributions of volume, surface and step atoms. To disentangle these contributions is an ongoing challenge of materials science. Here we introduce a method enabling the identification. of the remarkably different contributions of surface and perimeter atoms to the magnetic anisotropy energy of two-dimensional nanostructures. Our method uses the generally nonlinear relationship between perimeter length and surface area. Atomic-scale characterization of the morphology of ensembles of polydisperse nanostructures, combined with in situ measurements of their temperature-dependent magnetic susceptibility, gives access to the role played by the differently coordinated atoms. We show for Co nanostructures on a Pt(111) surface that their uniaxial out-of-plane magnetization is entirely caused by edge atoms having 20 times more anisotropy energy than their bulk and surface counterparts. Identification of the role of perimeter and surface atoms opens up unprecedented opportunities for materials engineering. As an example, we separately tune magnetic hardness and moment in bimetallic core-shell nanostructures.