A compass has a small magnet balanced on its needle. The Earth has two magnetic poles, and the magnet is attracted to its polar opposite at the North Pole.
The Earth's magnetic fields make compass operation possible, but it is not truly known why these fields exist. The Earth's core consists of super-pressurized molten iron that has been forced into a solid by intense heat and pressure. Convection from the Earth's core, along with the planet's rotation, causes the mantle to move in a rotational pattern, creating a magnetic field around the planet. However, the field is very weak, so compass needles, for example, must be installed on frictionless pivots, since the attraction is not strong enough to overcome much friction.