The first major wall was built during the reign of Qin Shi Huangdi, the first emperor of China during the Qin (Ch'in) Dynasty (221 B.C - 206 B.C.). It was created by joining several existing walls built previously by regional governments. This first wall was built much further north than the current Great Wall, and made of materials that have largely dissappeared over time.
Wall that can still be seen today was built during the Ming Dynasty (1368-1644), on
a much larger scale and made of stone on the sides and top. The wall housed garrisons, signal fires, and a messenger and postal service. The primary purpose was to make it difficult and slow for nomadic armies to get their horses across the wall. Without their horses the Huns were not a serious military threat. It is 4000 miles long, or 6400 km., and is visible from Earth orbit.