The compass is an instrument to determine direction, taking advantage of the Earth's magnetic polarity. It consists of a small bar magneta magnetized needleallowed to spin freely so as to point in the direction of magnetic north. A disc under the needle or around the edge of the device displays markings for north, south, east, and west. When the marking for north is aligned with the needle, a direction may be read.

In addition to revolutionizing navigation, the magnetic compassvariations of which came to be known as the mariner's compassmade surveying and cartography more accurate, being the first tool used to make charts from direct observation. While drawing a coastline, a mapmaker could take multiple readings from a compass to determine its direction. This did not represent ultimate accuracy, but it was an improvement over freehand methods.

The origins of the compass are lost to history. It probably was by accident that the Chinese, sometime before CE 1040, discovered that an iron needle rubbed on a lodestone (a variety of magnetite with natural magnetism), if allowed to float freely on water on a piece of straw, would always point to the same direction (the Chinese aligned their compasses to the south). The Chinese themselves did not use the compass for navigation but for feng shui, a practice that assigns spiritual properties to the four different directions; compasses were used to align buildings in the most propitious direction. The Chinese may have introduced the compass to Arabs and other Muslims, who made use of it before Europeans.

One of the earliest accounts of European contact with the compass comes from Petrus Peregrinus de Maricourt, a French Crusader, who wrote of it in the mid-13th century. For the ancient seafarer it was more important to understand the winds than to make abstract calculations, so early mariner's compasses were marked with the 12 primary winds instead of the four directions. It was in Amalfi, Italy, between 1295 and 1302, that the compass as we know it was developed. Yet, when first introduced, its functioning was so mysterious that many Europeans thought it a work of the devil or of evil spirits, and captains sometimes had to keep the presence of a compass on board ships secret from crews.

As use of the compass became more advanced, navigators came to understand the difference between true north and magnetic north, and to recognize regional variations in Earth's magnetic field. A variation on the compass, the gyrocompass, an electronic device using a gyroscope, can determine true north as opposed to magnetic north. Compasses are sometimes mounted in other instruments, such as the transit used in surveying.