Earth's Magnetic Field
The reason why a compass works is more interesting. It turns out that you can think of the Earth as having a gigantic bar magnet buried inside. In order for the north end of the compass to point toward the North Pole, you have to assume that the buried bar magnet has its south end at the North Pole, as shown in the diagram at the right. If you think of the world this way, then you can see that the normal "opposites attract" rule of magnets would cause the north end of the compass needle to point toward the south end of the buried bar magnet. So the compass points toward the North Pole.
To be completely accurate, the bar magnet does not run exactly along the Earth's rotational axis. It is skewed slightly off center. This skew is called the declination, and most good maps indicate what the declination is in different areas (since it changes a little depending on where you are on the planet).
The magnetic field of the Earth is fairly weak on the surface. After all, the planet Earth is almost 8,000 miles in diameter, so the magnetic field has to travel a long way to affect your compass. That is why a compass needs to have a lightweight magnet and a frictionless bearing. Otherwise, there just isn't enough strength in the Earth's magnetic field to turn the needle.
The "big bar magnet buried in the core" analogy works to explain why the Earth has a magnetic field, but obviously that is not what is really happening. So what is really happening?
No one knows for sure, but there is a working theory currently making the rounds. As seen on the above, the Earth's core is thought to consist largely of molten iron (red). But at the very core, the pressure is so great that this superhot iron crystallizes into a solid. Convection caused by heat radiating from the core, along with the rotation of the Earth, causes the liquid iron to move in a rotational pattern. It is believed that these rotational forces in the liquid iron layer lead to weak magnetic forces around the axis of spin.
It turns out that because the Earth's magnetic field is so weak, a compass is nothing but a detector for very slight magnetic fields created by anything. That is why we can use a compass to detect the small magnetic field produced by a wire carrying a current (see How Electromagnets Work).
Now let's look at how you can create your own compass.