Magnetic compass was invented in China between the 2nd century BC and 1st century AD, in the times when the Han dynasty ruled. It was used at first as a tool for geomancy - in feng shui, and only later as an instrument for navigation and orientation. The first compasses were made of lodestone, a naturally magnetized ore of iron. Magnetic compass is a pretty simple instrument that has a magnetic needle or a magnetized bar can turn freely upon a pivot and align itself with Earth's magnetic field and indicate the direction of the magnetic north of a planet's magnetosphere. From that, cardinal points of north, south, east and west are very easy to determine.
Before the magnetic compass was invented people new about magnetic properties of magnetite and lodestone but they were regarded as curiosities of nature. Plinius the Elder (23-70 AD) wrote that shepherd Magnes reported that the nails of his shoes and the iron point of his staff clung to the rocks on Mount Ida which were made of magnetite. Thales of Milet thought that magnetite had a soul that attracted stones like iron. Wang Xu, Chinese writer from 4th century, mentions that “lodestone attracts iron”. Between 70 and 80 AD, Chinese use “south pointing spoon” which “when thrown upon the ground, it comes to rest pointing at the south”. Chung Hua Ku Chin Chu text written by Ma Kao, mentions magnetized needle as a "mysterious needle" between 923 and 926. Needle from this text is shaped like a tadpole and it is thought that this marks transition between compasses made in the shape of "lodestone spoons" into "iron needles".
Compass is used for the first time as a navigational device during the Song Dynasty and is mentioned for the first time in this role in the book dated to 1040-44. It was in the shape of a fish, it floated in the bowl of water and it pointed south. At the sea, compass is used, again in China, in 1117. Lesser used compass for this was a dry compass.
Magnetic compass appeared in Europe somewhere between 1187 and 1202 according the texts texts De utensilibus and De naturis rerum. Floating compass was used for astronomical purposes while dry compass was used for seafaring. With advancements in dead reckoning methods it improved seafaring of that time. Before compass sea travel was done between October and April and compass prolonged the sailing season across the whole year.
The Muslim world imported compass in 13th century. There, it was also used for navigation and for astronomy like in Europe but it was also used as a "Qibla (Kabba) indicator" to find the direction to Mecca. the Syrian astronomer and timekeeper Ibn al-Shatir, improved compass by combining it with a universal sundial, to be used as an improved Qibla indicator and for finding the times of salat prayers.
Today magnetic compass is still used for orientation and navigation but it has more modern look than its predecessors and it is made from modern materials.