In physics, a magnetic field is the relativistic part of an electric field, as Einstein explained in 1905. When an electric charge is moving from the perspective of an observer, the electric field of this charge due to space contraction is no longer seen by the observer as spherically symmetric due to non-radial time dilation, and it must be computed using the Lorentz transformations. One of the products of these transformations is the part of the electric field which only acts on moving charges - and we call it the "magnetic field".
The quantum-mechanical motion of electrons in atoms produces the magnetic fields of permanent ferromagnets. Spinning charged particles also have magnetic moment. Some electrically neutral particles (like the neutron) with non-zero spin also have magnetic moment due to the charge distribution in their inner structure. Particles with zero spin never have magnetic moment.