Is a good question and actually it has more than one answer, depending on the interpretation of the question.
The first segments were built in the fifth century BC and the last contributions of the Great wall of China where build in the sixteenth century AD.
The Great Wall of China was built in a series of sections as a defense against invading nomads along the northern border of China beginning in the fifth century BC. This trend continued until 221 BC when Emperor Qin Shi Huang, after defeating neighboring states that opposed him, centralized authority in China and unified the country.
During the relatively short history of Qin rule, Emperor Qin ordered that a new wall be built along the northern border to defend against the Xiongnu tribe from the north, connecting the existing sections of the wal along the new northern border of the consolidated territory. The Great Wall of China was constructed of primarily local materials, with sections in the plains being constructed of rammed earth while mountainous areas relied on stones from the surrounding landscape.
Unfortunately, no records of how long the completed original Qin wall was to be or the actual boundaries have survived to the present, and much of the original wall has eroded over the centuries leaving very little information to support the facts. For several centuries the Sui, Han, Jin and Northern dynasties continued to repair and improve numerous sections of the Great Wall to defend their territories from invading northern tribes.
After this period of history, the Ming Dynasty renewed the practice of wall building after suffering defeat by the Oirats in 1449. This defeat, coupled with an inability to gain control over the Mongolian and Manchurian tribes, led to the Ming decision to reestablish building the wall along China's northern border. The Ming Dynasty chose to use stone and bricks to construct and fortify the Wall, making it much stronger than what was constructed by the Qin, paying particular attention to the area near Beijing. This fact was the result of the especially fierce raids by the Mongols that persisted during much of the thirteenth century.
Somewhere around the beginning of the seventeenth century near the end of the Ming Dynasty, the Great Wall was instrumental in defending China from invasion by the Manchu. In 1644, General Wu Sangui, a Ming military officer, who in an act of revolt against the Shun Dynasty, opened the gates in the wall at Shanhaiguan, allowing the Manchus entry through the wall. They proceeded to conquer the ruling Shun Dynasty and established the Qing Dynasty in short order. During the Qing Dynasty, Mongolia was incorporated into the empire, alleviating the need for the Great Wall, effectively ending additional building and maintenance on the wall.