Datong is a prefecture-level city in northern Shanxi Province in the People's Republic of China. It is located in the Datong Basin at an elevation of and borders Inner Mongolia to the north and west and Hebei to the east. As of the 2020 census, it had a population of 3,105,591 of whom 1,790,452 lived in the built-up (or metro) area made of the 2 out 4 urban districts of Pingcheng and Yungang as Yunzhou and Xinrong are not conurbated yet. The area of present-day Datong was close to the state of Dai, which was conquered by the Zhao clan of Jin in 457 BC. It was a frontier land between the agricultural Chinese and the nomads of the Great Steppe. The area was well known for its trade in horses. The area of present-day Datong eventually came under the control of the Qin dynasty, during which it was known as Pingcheng County (平城县) and formed part of the Qin commandery of Yanmen. Pingcheng County continued under the Han dynasty, which founded a site within present-day Datong in 200 BC following its victory against the Xiongnu nomads at the Battle of Baideng. Located near a pass to Inner Mongolia along the Great Wall, Pingcheng blossomed under Han rule and became a stop-off point for camel caravans moving from China into Mongolia and beyond. It was sacked at the end of the Eastern Han. Pingcheng became the capital of the Xianbei-founded Northern Wei dynasty from AD 398–494. The Yungang Grottoes were constructed during the later part of this period (460–494). During the mid to late 520s, Pingcheng was the seat of Northern Wei's Dai Commandery. During the Tang dynasty, Datong became the seat of the Tang prefecture of Yunzhou, and the original Guandi temple was built. The city was renamed Datong in 1048. It was the Xijing ("Western Capital") of the Jurchen Jin dynasty prior to being sacked by the Mongols. Datong later came under the control of the Ming dynasty, serving as an important Ming military stronghold against the Mongols to the north. During the Ming period, many of Datong's notable historical structures such as the Drum Tower and the Nine-Dragon Wall were built.