We perform low-temperature spin-polarized scanning tunneling microscopy (SP-STM) and spectroscopy measurements in magnetic fields to gain new insights into nanomagnetism. We use the magnetic field to change and control magnetizations of a sample and a magnetic tip, and measure the magnetic hysteresis loops of individual Co nano-islands on Cu(111). We also exploit the high spatial resolution of SP-STM in magnetic fields to measure maps of the differential conductance within a single Co nano-island. In connection with ab initio calculations, we find that the spin polarization is not homogeneous but spatially modulated within the nano-island. We ascribe the spatial variation of the spin polarization to spin-dependent electron confinement within the Co nano-island.