The compass evolved in China in the first century AD from brass divining boards used to determine the best locations for buildings, so that they would be in harmony with the spirits of earth and water. The divining boards had a magnetized needle that aligned itself in a north-south direction on a polished surface. A thousand years later, Chinese mariners took the magnetized needles on board ships to guide them.
Because level surfaces cannot be found on a rocking ship, the needles were floated in small stone basins of water. The magnetized needle would slowly drift into the north-south directions. With these compasses, pilots could stay the course over long distances.
The compass was introduced to the Arab world and Europe during the Northern Song Dynasty (960-1127). Before its invention, navigators had to depend on the positions of the sun, the moon and the polestar for their bearings, which of course was impossible when skies were not clear. The spread of the compass to Europe opened the oceans of the world to travel and led to the discovery of the New World.
Learn more: Compass, China, 220 BCE