What a magnet does
A magnet attracts certain metals, most familiarly iron, and it can attract or repel other magnets. Every magnet has two ends, called poles, labeled north and south. Opposite poles attract and like poles repel. If you cut a bar magnet in half, you do not get a separate north and south; you get two smaller magnets, each with both poles. No isolated magnetic pole has ever been observed.
Magnetism comes from the motion of electric charge. In atoms, electrons have a property that makes each one act like a tiny magnet. In most materials those tiny magnets point in random directions and cancel out. In iron and a few other materials, they can line up in regions, and when the regions are aligned, the object becomes a permanent magnet.
Magnetic fields
A magnetic field is the region around a magnet, or around a moving charge, in which magnetic forces can be felt. You cannot see it, but you can reveal its pattern. Sprinkle iron filings on a sheet of paper over a bar magnet, and the filings arrange themselves into curved lines that loop from one pole to the other. Those are a visual picture of the field, and the field is stronger where the lines are closer together.
A magnetic field is also produced by an electric current. A wire carrying current has a magnetic field circling around it, and coiling the wire into a loop concentrates the field, which is how electromagnets work. Conversely, moving a magnet near a wire can push charges along it. These links between electricity and magnetism are the basis of generators and electric motors, and they are touched on in the explanation of electric current.
Earth as a magnet
Earth has a magnetic field that extends far out into space. A rough picture is that of a bar magnet inside the planet, though no such bar exists. The interior is far too hot for iron to keep permanent magnetism. Instead, scientists think the field is generated by the motion of molten iron-rich metal in Earth’s outer core, which acts as a self-sustaining dynamo. Convection in the core, together with the planet’s rotation, is thought to drive these motions. Many details are still being studied, and the field is known to change over time.
The field has a practical benefit. It deflects much of the stream of charged particles flowing from the Sun, which would otherwise strip away more of the atmosphere and increase radiation at the surface. Where some particles are guided toward the poles, they can cause auroras.
How a compass works
A compass is a small, lightweight magnet, the needle, that is free to turn. Like any magnet in a field, the needle experiences a turning force that lines it up with the field. Because Earth’s field near the surface runs roughly north to south, the needle settles in that direction.
There is a naming quirk. The end of a compass needle that points to the north is called its north-seeking pole. Since opposite poles attract, the magnetic pole near the Arctic must be, physically, a magnetic south pole. It is still called the north magnetic pole because of where it is located.
Magnetic north versus true north
A compass does not point exactly to the geographic North Pole, which is the point where Earth’s rotation axis meets the surface. It points toward the magnetic north pole, which is in a different place and slowly moves. The angle between the two directions at a particular location is called magnetic declination. It varies from place to place and changes over the years, so navigators use local, up-to-date information to correct for it.
Other things can disturb a compass too. Nearby iron objects, electrical wiring and other magnets can pull the needle off course. Near the magnetic poles, the field lines point steeply into the ground, so ordinary compasses become unreliable.
Satellite-based systems have replaced the compass in much navigation, as described in GPS navigation, though many people still carry a magnetic compass as a simple backup that needs no battery.
A field that changes
Earth’s field is not constant. The magnetic poles wander, and over geological time the field has reversed direction many times, with north and south magnetic poles swapping. The intervals between reversals are irregular, and the last full reversal happened hundreds of thousands of years ago. Rocks that formed from cooling lava can preserve the field direction at the time they formed, and these records helped scientists develop the theory of plate tectonics.
Some animals may use the field to help them find their way. Research suggests that certain birds, sea turtles and other species respond to it, but the mechanisms are not fully understood, and the topic is still under investigation. It is one of several clues studied in work on animal migration.