In a very classical picture of an atom (this is not the correct quantum mechanical picture, but it can nevertheless give us some insight to this topic...), the electrons orbit the nucleus in circular orbits which form current loops (any charge moving in a closed loop forms a current loop!), each loop producing a magnetic field as discussed in the previous section. In atoms where the orbitals are filled, the magnetic fields produced by the various current loops

Figure 17.9

tend to cancel one another (the orbits tend to pair up, clockwise current flow with counterclockwise current flow, so the magnetic fields will cancel), so the atom on the whole tends not to produce a magnetic field.  However, when the orbitals are not filled and the electrons are not all paired (clockwise with counterclockwise),  then there tends to be a net magnetic field produced by the atom.  The atom as a whole then acts like a magnetic dipole.  (See Fig. 17.9 showing an electron orbit in an atom. Note the  direction of the electronís velocity and the corresponding direction of the current flow. Why are they opposite to one another?

Ordinarily, even in materials made up of atoms having a net magnetic dipole (so-called magnetic dipole moments), the atomic dipoles themselves tend to be randomly oriented within the  material, and so the net magnetic field produced by the material is zero.  However, some special materials, called ferromagnetic materials, have magnetic domains within which all  of the atomic magnetic dipole moments tend to be more-or-less

Figure 17.10

aligned. If these domains are randomly oriented, as shown in Fig. 17.10 (the arrows show the directions of atomic magnetic dipole magnetic fields; the different colors are used simply to help differentiate the different regions), then the net magnetic field of the material is still zero.

However, if a strong external magnetic field is produced in the region of the material, the resulting magnetic force on the atomic dipoles can overcome internal friction between the magnetic domains in a ferromagnetic material and cause the domains to rotate until they tend to more-or-less align themselves with the external magnetic field. (Thermal agitation keeps us from ever getting a perfect alignment of domains!)  The net, external magnetic field (the magnetic field measured outside of the material) is then a combination of the original external magnetic field (the one that rotated the magnetic domains in the ferromagnetic material) plus a very large magnetic field produced by the material itself (due to the alignment of its magnetic domains, so all of the atomic dipoles produce magnetic fields that tend to add to one another). 

If the external magnetic field is now turned off, instead of going back to their randomly oriented positions, the magnetic domains within the ferromagnetic material tend to stay  more-or-less aligned.  (The internal friction between neighboring domains keeps them from randomizing.)  We are thus left with a material which produces a strong magnetic field.  Such  a material is called a ferromagnet or, more commonly, a permanent magnet.  The magnetic domains will remain aligned until randomized by thermal agitation or by some other  external force which can do work in rotating the domains within the material.  (For example, heating up a magnet or whacking it with a hammer can remove the materialís magnetic effects!)