The earliest remnants of human habitation in the Beijing municipality are found in the caves of Dragon Bone Hill near the village of Zhoukoudian in Fangshan District, where the Peking Man lived. Homo erectus fossils from the caves date to 230,000 to 250,000 years ago. Paleolithic homo sapiens also lived there about 27,000 years ago. There were cities in the vicinities of Beijing by the 1st millennium BC, and the capital of the State of Yan, one of the powers of the Warring States Period (473-221 BC), Ji, was established in present-day Beijing.
In 936, the Later Jin Dynasty (936-947) of northern China ceded a large part of its northern frontier, including modern Beijing, to the Khitan Liao Dynasty. In 938, the Liao Dynasty set up a secondary capital in what is now Beijing, and called it Nanjing (the "Southern Capital"). In 1125, the Jurchen Jin Dynasty conquered Liao, and in 1153 moved its capital to Liao's Nanjing, calling it Zhongdu, the "central capital." Zhongdu was situated in what is now the area centered around Tianningsi, slightly to the southwest of central Beijing. Some of the oldest existing relics in Beijing, such as the Tianning Temple, date to the Liao.
Mongol forces burned Zhongdu to the ground in 1215. Later in 1264, in preparation for the conquest of all of China to establish the Yuan Dynasty, Kublai Khan decided to rebuild it slightly north to the center of the Jin capital, and in 1272, he made this city his capital as Dadu or Daidu to the Mongols, otherwise spelled as Cambaluc or Cambuluc in Marco Polo's accounts. Construction of Dadu finished in 1293. The decision of Kublai Khan greatly enhanced the status of a city that had been situated on the northern fringe of China proper. The center of Dadu was situated slightly north of modern central Beijing. It centered on what is now the northern stretch of the 2nd Ring Road, and stretched northwards to between the 3rd and 4th Ring Roads. There are remnants of the Yuan-era wall still standing and they are known as the Tucheng (literally, the 'earth wall').
Ming and Qing period
In 1368, Zhu Yuanzhang, soon after declaring himself the first emperor of the Ming Dynasty, sent an army toward Dadu, still held by the Yuan. The last Yuan emperor fled north to Shangdu, and Zhu razed the Yuan palaces in Dadu to the ground. The city was renamed Beiping, or "northern peace" in the same year,and Shuntian prefecture was established in the area around the city. In 1403, the third Ming emperor - the Yongle Emperor - renamed this city Beijing, or "northern capital", and designated Beijing the co-capital alongside the (then) current capital of Nanjing. Beijing was the subject of a major construction project for a new Imperial residence, the Forbidden City that lasted nearly 15 years (1406 to 1420). When the palace was finished, the Yongle Emperor ceremoniously took up residence. From 1421 onwards, Beijing, also known as Jingshi, was the "official" capital of the Ming Dynasty while Nanjing was demoted to the status of secondary capital. This system of dual capitals (with Beijing being vastly more important) continued for the duration of the Ming Dynasty. Thirteen of the sixteen Ming Emperors are buried in elaborate tombs near Beijing.
By the 15th century, Beijing had essentially taken its current shape. It is believed that Beijing was the largest city in the world from 1425 to 1650 and from 1710 to 1825. Other notable buildings constructed during the Ming period include the Temple of Heaven (built by 1420). The Tiananmen Gate, now a state symbol of China and featured on its emblem, was first built in 1420, and rebuilt several times later. Tiananmen Square was built in 1651 and enlarged in 1958.
The end of the Ming came in 1644 when, for 40 days, Li Zicheng's peasant army captured Beijing and overthrew the Ming government. When the powerful Manchu army arrived at the outskirts of the city, Li and his followers abandoned the city and as a result the Manchu forces, under Prince Dorgon, captured Beijing without a fight.
Prince Dorgon established the Qing Dynasty as a direct successor to the Ming, and Beijing remained China's capital. The Qing Emperors made some modifications to the Imperial residence, but in large part, the Ming buildings and the general layout remained unchanged. Beijing at this time was also known as Jingshi, which corresponded to the Manchu Gemun Hecen with the same meaning. The classic Chinese novel Dream of the Red Chamber is set in Beijing during the early years of Qing rule (the end of the 1600s).
The Xinhai Revolution of 1911, aimed at replacing Qing rule with a republic, originally intended to establish its capital at Nanjing. After high-ranking Qing official Yuan Shikai forced the abdication of the Qing emperor in Beijing and ensured the success of the revolution, the revolutionaries in Nanjing accepted that Yuan should be the president of the new Republic of China and the capital remains at Beijing. Yuan gradually consolidated power and became by 1915 the new emperor of China, but died less than a year into his reign. China then fell under the control of regional warlords, and the most powerful factions fought frequent wars to take control of the capital at Beijing. Following the success of the Kuomintang (KMT)'s Northern Expedition, which pacified the warlords of the north, Nanjing was officially made the capital of the Republic of China in 1928, and Beijing was renamed Beiping (Peip'ing) on 28 June that year, in English meaning "northern peace" or "north pacified". During the Second Sino-Japanese War, Beiping fell to Japan on 29 July 1937, and was made the seat of the Provisional Government of the Republic of China, a puppet state that ruled the ethnic Chinese portions of Japanese-occupied northern China; the government was later merged into the larger Wang Jingwei Government based in Nanjing.
On 31 January 1949, during the Chinese Civil War, Communist forces entered Beijing without a fight. On 1 October of the same year, the Communist Party of China, under the leadership of Mao Zedong, announced in Tiananmen the creation of the People's Republic of China and renamed the city back to Beijing. Just a few days earlier, the Chinese People's Political Consultative Conference had decided that Beijing would be the capital of the new government.
At the time of the founding of the People's Republic, Beijing Municipality consisted of just its urban area and immediate suburbs. The urban area was divided into many small districts inside what is now the 2nd Ring Road.