If you've read How Electromagnets Work, you know that an electrical current moving through a wire creates a magnetic field. Moving electrical charges are responsible for the magnetic field in permanent magnets as well. But a magnet's field doesn't come from a large current traveling through a wire -- it comes from the movement of electrons.
Many people imagine electrons as tiny particles that orbit an atom's nucleus the way planets orbit a sun. As quantum physicists currently explain it, the movement of electrons is a little more complicated than that. Essentially, electrons fill an atom's shell-like orbitals, where they behave as both particles and waves. The electrons have a charge and a mass, as well as a movement that physicists describe as spin in an upward or downward direction. You can learn more about electrons in How Atoms Work.
Generally, electrons fill the atom's orbitals in pairs. If one of the electrons in a pair spins upward, the other spins downward. It's impossible for both of the electrons in a pair to spin in the same direction. This is part of a quantum-mechanical principle known as the Pauli Exclusion Principle.
Even though an atom's electrons don't move very far, their movement is enough to create a tiny magnetic field. Since paired electrons spin in opposite directions, their magnetic fields cancel one another out. Atoms of ferromagnetic elements, on the other hand, have several unpaired electrons that have the same spin. Iron, for example, has four unpaired electrons with the same spin. Because they have no opposing fields to cancel their effects, these electrons have an orbital magnetic moment. The magnetic moment is a vector -- it has a magnitude and a direction. It's related to both the magnetic field strength and the torque that the field exerts. A whole magnet's magnetic moments come from the moments of all of its atoms.
In metals like iron, the orbital magnetic moment encourages nearby atoms to align along the same north-south field lines. Iron and other ferromagnetic materials are crystalline. As they cool from a molten state, groups of atoms with parallel orbital spin line up within the crystal structure. This forms the magnetic domains discussed in the previous section.
You may have noticed that the materials that make good magnets are the same as the materials magnets attract. This is because magnets attract materials that have unpaired electrons that spin in the same direction. In other words, the quality that turns a metal into a magnet also attracts the metal to magnets. Many other elements are diamagnetic -- their unpaired atoms create a field that weakly repels a magnet. A few materials don't react with magnets at all.
This explanation and its underlying quantum physics are fairly complicated, and without them the idea of magnetic attraction can be mystifying. So it's not surprising that people have viewed magnetic materials with suspicion for much of history. In the next section, we'll take a look at the powers ascribed to magnets, as well as what they can and can't do.