  Neutron stars contain persistent, ordered magnetic fields that are the
strongest known in the Universe. However, their magnetic fluxes are similar to
those in magnetic A and B stars and white dwarfs, suggesting that flux
conservation during gravitational collapse may play an important role in
establishing the field, although it might also be modified substantially by
early convection, differential rotation, and magnetic instabilities. The
equilibrium field configuration, established within hours (at most) of the
formation of the star, is likely to be roughly axisymmetric, involving both
poloidal and toroidal components. The stable stratification of the neutron star
matter (due to its radial composition gradient) probably plays a crucial role
in holding this magnetic structure inside the star. The field can evolve on
long time scales by processes that overcome the stable stratification, such as
weak interactions changing the relative abundances and ambipolar diffusion of
charged particles with respect to neutrons. These processes become more
effective for stronger magnetic fields, thus naturally explaining the magnetic
energy dissipation expected in magnetars, at the same time as the longer-lived,
weaker fields in classical and millisecond pulsars.
