The Great Wall of China (Wanli Changcheng 萬里長城; literally "Ten Thousand Leagues Long Fortification") is one of the most outstanding buildings of mankind, sometimes called the eight world wonder and said to be the only human work that can be seen from the moon (which is, of course, not true).
The part of the Great Wall we can admire today north of Beijing, are the reconstructed remnants of the Ming Dynasty wall. But this wall is only the last wall-fortification in a long tradition of wall building.
The oldest fortification walls of China were erected as an instrument of defense between the kingdoms of the Warring States period from the 5th to the 3rd century BC, that means, to defend Chinese against Chinese, not against "barbarians", like later. Today, it is possible to reconstruct five of these inner-China walls: the walls of Qi 齊 (modern Shandong), Chu 楚 (modern Hubei), Qin 秦 (modern Shaanxi), Yan 燕 (modern Hebei), Zhao 趙 (modern Shanxi), and Wei 魏 (modern Henan).
Very famous is the Great Wall built by the First Emperor of Qin in 215 BC who was told by a magician that barbarians from the north would be able to attack his empire. The work to throw back the "barbarians" and to erect a defensive wall was undertaken by his general Meng Tian 蒙恬. Not much is left of this wall (we know a part made from unhewn stones near Baotou 包頭/Inner Mongolia), but we are able to trace back the course of his wall from Lintao 臨洮/Gansu to the Liaodong Peninsula 遼東/Liaoning that partially used older walls, especially in the east. Thousands of slaves and forced corvée workers are said to have died during the erection of the Qin wall - but we can imagine that the situation during the following dynasties was not very different.
The first very important walls are that of the Han Dynasty. The offensive foreign politics of Emperor Han Wudi lead to the opening of the "western corridor" to Inner Asia and the begin of an intense trade with the Central Asian countries. A traveller named Zhang Qian 張騫 was the first Chinese to discover the importance of these Inner Asian kingdoms. The trade route to the west is known as the Silk Road. Nomad tribes north of the Chinese empire, in modern Mongolia, steadily attacked the towns and market places of the border region. To prevent the nomad tribes from their raids on Chinese soil, the Chinese government developed two kinds of political measures: tributary presents like silk, alcohol, later porcelain and tea, or even princesses (heqin 和親, "peace by marriage"), to appease the martial tribes; the second method was the offensive war undertaken by Emperor Han Wudi. His generals destroyed the mighty chieftain of the Xiongnu 匈奴 tribes, advanced into new territory and had erected defensive fortification walls in the years of 127 BC and 105 BC. These walls were very simply constructed with the main materials tamped loam, and straw. The forts along the wall (the most important Han Dynasty fort is the Yumenguan Fort 玉門關/Gansu) were not only constructed to prohibit the northern barbarians to attack Chinese border towns. Signal towers had the objective to quickly inform a fort or the capital from a barbarian attack. The third objective of the Han Dynasty walls was the protection of the markets along the road to the west like the newly founded commandery of Dunhuang 敦煌/Gansu, or the storehouse at Hecang 河藏/Gansu. To ensure the living of the troops along the wall-fortification, the soldiers were partially obliged to engage in agriculture, partially, peasants were resettled into the frontier-near military agro-colonies (tuntian 屯田). The Han Dynasty wall reached far into the west, probably until Lake Lop Nur/Xinjiang (Chinese: Luobu Bo 羅布泊).
Less important - or less famous - are the walls of the Northern Wei Dynasty from the 5th century AD. After repelling the Rouran 柔然 nomads, walls were erected along the norther frontier of the Wei empire, a dynasty whose founders were barbarians themselves only a few centuries before. An official named Gao Lü 高閭 demonstrated the advantages of a fortification wall: stationary defense instead of mobile defense; better reconnaissance of military attacks; no more robbing of kettle along the borders; better economical growth by less raids and less defense spendings; and less tied up political work by better protection of the borders. The short-lived Northern Qi and Sui Dynasties also erected provisory walls against the Eastern Türks (Chinese: Tujue 突厥).
The cultural openness of the Tang Empire was followed by a political and military openness. The whole period of Tang, from about 600 to 900 AD, showed an economical prosperity by the open trade routes to Inner Asia. No fortification walls were necessary.
The Song Empire - although always in a defensive political situation against the empires of Liao, Western Xia, and Jin - did not build fortification walls. The whole Song Dynasty had a strict orientation to appeasement politics and made intensive use of tributary presents (or rather, in fact, real tributs to the neighbouring empires in the north). A second reason why the Song emperors did not build fortification walls, was the advancec military technology of the Liao and Jin empires. The old nomad tribes like the Xiongnu or Rouran made use of cavaly and bow and arrow. Their undertakings were raids of the borders towns, their target was kettle and other valuables. The modern rulers of the Liao and Jin empires were no more nomads, but real emperors of a empire modeled after the Chinese Song empire. Their target was territory, their technology was armored cavalry.
After the Jin Dynasty conquered whole northern China, they started to erect a long fortification wall along their northern frontier from Qiqihar 齊齊哈爾/Heilongjiang to Baotou/Inner Mongolia. The technology of this wall is very different to the old ones: it was covered with hewn stones, crowned with battlements and parapets, and protected with moats. But even these technologically advanced fortifications were unable to protect China from the Mongols.
The follower of the Mongol Yuan Dynasty, the Ming Dynasty, was not very decisive in the question how to deal with the nomad tribes - especially the Mongols. Only bad experience with the restrengthening of the Mongol tribes under the command of Altan Khan lead to the construction of the famous Ming Wall from the 1530es on (the oldest parts are from 1485), but especially at the end of the 16th century. The Ming Walls are purely defensive and strictly follow the hill crests in mountainous areas. The building material is - at least in the famous eastern parts - burned brick. The Manchus were only able to enter Chinese soil because a traitor opened the gates to them in 1644.
From the 1980es on, large parts of the Great Wall(s) were reconstructed, and today, the eastern wing of the Wall is one of the most important tourist attractions of China, especially the part near Badaling 八達岭, Gubeikou 古北口, Simatai 司馬台, and Mutianyu 慕田峪 (all near Beijing), and the Fortresses Shanhaiguan 山海關/Hebei and Juyongguan 居庸關/Beijing. The western part of the Ming Dynasty Great Wall is the Fortress Jiayuguan 嘉峪關/Gansu.