The first known use of Earth's magnetic field in this way occurred in ancient China as a spectacle. Arrows were cast similarly to dice. These magnetised arrows aligned themselves pointing north, impressing the audience.
Curiously this trick did not seem to get used by the Chinese for naval navigation. The knowledge of the behavior of long thin magnets and lodestones had to move to Europe for that to occur. European naval powers were quick to identify the value of having a compass onboard. Celestial navigation used the constellations and known stars to identify directions. This was of little or known use in foggy conditions, with overcast sky or during the day. Early compasses often consisted of a natural lodestone which was placed on a float in protected container of water.
A magnetic rod is required. This can be created by aligned an iron or steel rod with Earth's magnetic field and then tempering or striking it. However, this method produces only a weak magnet so other methods are preferred. This magnetised rod or needle is then placed on a low friction surface to allow it to freely pivot to align itself with the magnetic field. It should be labeled and generally has a pointer to North.
A compass can be used in conjunction with a clock and a sextant to provide a very accurate navigation capability. This device greatly improved maritime trade by making travel safer and more efficient.