The earth is a giant magnet.
A compass has a tiny bar magnet in it.
If you tie a magnet onto a piece of wood and put it in water it will float. The magnet will then turn itself so the north pole points towards Earth's south pole.