Historically, the capitals of ancient Chinese dynasties have changed over time. These include Anyang, Nanjing, Yan'an, Luoyang, and the longest-serving, Xi'an. It was in Xi'an that China's first emperor ruled. It is also near Xi'an that the emperor's tomb, a giant pyramid surrounded by a terracotta army, was discovered.
The Xian City Walls still stand strong today
The Chinese pyramid believed to be the tomb of Qin Shihuang (the First Emperor of China)
Terracotta Army
So why move to Beijing, which is relatively far north?
Until the 10th and 11th centuries, Beijing was a trading city. It served northern trade with steppe tribes. However, in 1213 CE, the city was destroyed by Genghis Khan's forces.
Beijing was rebuilt by Genghis Khan's grandson, Kublai Khan. He founded the Yuan dynasty, which ruled China, Korea, and Mongolia. It was Kublai Khan who later invaded Java.
Yuan Dynasty's Power
Kublai Khan called Beijing Dadu or Daidu at the time. Some Mongols also called it Khanbaliq. Looking at the map of the Yuan dynasty at the time, Kublai's choice of Dadu or Beijing is understandable, as it was located roughly in the center of Yuan rule.
Kublai Khan
After the Yuan dynasty collapsed and was replaced by the Ming (1368–1644), China's capital remained unchanged. The Ming did indeed use two imperial cities: Beijing (Peking) and Nanjing. However, their largest palace was in Beijing. The Qing (Manchu) dynasty, which succeeded the Ming, also used Beijing as their capital.
During the Chinese revolution and division until after World War II, Nanjing served primarily as China's administrative center, while Shanghai served as its business center.
However, after the Communists won, they chose Beijing as their seat of government. Some rumors suggest that Beijing was Mao's personal choice, possibly because he felt Nanjing was too closely associated with Chiang Kai-shek's government. Actually, we might never really know about this.