Archaeologists have found human fossils from the Stone Age at the village of Xujiayao, Guzheng township in Yanggao county. It is believed that Xujiayao Man was the descendant of Beijing Man, who settled there when they encountered a lake in their westwards migration around 100,000 years ago.
The region of Datong was home to the Di people in northern China during the Spring and Autumn Period (770-476 BC). Di people mainly consisted of nomads such as the Linhu and the Loufan, who lived by hunting.
Datong initially belonged to the State of Dai and later was annexed by the State of Zhao in the Warring States Period (475-221 BC).
The Western Han Dynasty (206 BC-AD 24): Datong adopted the system of prefectures and counties founded in the preceding Qin Dynasty (221-206 BC). Datong continued to belong to the prefectures of Yanmen and Dai.
The Eastern Han Dynasty (25-220): Datong designated Zhoumu in Chinese as the top administrative and military officer in an administrative region. Later, the office of Zhoumu was replaced by the title of inspector. Datong still belonged to the prefectures during the Eastern Han period.
The Wuhuan and Xianbei tribes lived in the Datong region during the Three Kingdoms Period (220-280).
Tongguang Temple was built in Datong, which was then called Pingcheng, during the reign of the Emperor Mingdi (58-75).
The northern part of the Datong region was occupied by Xianbei people during the Jin Dynasty (265-420). Meanwhile, its southern part belonged to Yanmen Prefecture, with headquarters in Guangwu. The prefecture governed counties of Guangwu, Guo, Wangtao, Pingcheng, Junren, Fanshi, Yuanping and Mayi.
Emperor Tuobagui of the Northern Wei Dynasty (386-534) moved his capital from Shengle in North China's Inner Mongolia autonomous region to Datong, then called Pingcheng, designated his era name as Tianxing, and appointed officials as Sizhou and Daiyin to govern the administrative region of the capital city and surrounding areas. Pingcheng consisted of a royal palace, the capital and its outer areas.
The Northern Wei Dynasty retained its capital in Datong for 97 years. A total of six emperors in a span of seven generations lived and worked there. The capital city was the political, economic and cultural center of northern China at that time. The dynasty later fell into two minor states, which were Eastern Wei and Western Wei, after a civil war.
The State of Northern Qi replaced Eastern Wei in 550. Datong belonged to Beiheng and Beishuo and there were no noticeable changes to its boundaries.
The State of Northern Zhou replaced Western Wei in 557. Northern Zhou abolished the prefecture and counties in Datong, developed Shuozhou Prefecture into Northern Shuozhou with an integration of military and administrative functions, and changed the name of Taiping county into Yunzhong county after it conquered Northern Qi in 577. The county of Lingqiu belonged to Yu Prefecture and was under the administration of Lingqiu.
The Sui Dynasty (581-618) divided its administrative regions into prefectures and counties when it reunified the whole country in 589. Datong belonged to the prefectures of Mayi and Yanmen.
The Tang Dynasty (618-907) adopted its predecessor’s practice of prefectures and counties during the early period of its establishment. The dynasty reestablished Beiheng county in former Hengan township when it defeated Liu Wuzhou, a warlord in late Sui Dynasty, in 621. Two years later, Yuzhou county was founded in Lingqiu of Yanmen Prefecture. Beiheng was abolished in 624. The counties of Yuzhong, Yuzhou and Shuozhou were under the administration of Hedong province. The headquarters of Yunzhou is located in Yunzhong county. Yunzhou was caught in a protracted war when the Tang Dynasty was plagued with military confrontations between regional warlords with competing interests in its late period. Later, Li Cunxu (Emperor Zhuangzong), who was the son of Li Keyong (a Shatuo military governor), conquered the State of Later Liang and proclaimed himself emperor of the Later Tang (923-936).
Kaiyuan Temple, a state-level Buddhist institute, was built in Datong during the reign of Emperor Xuanzong in the Tang Dynasty (618-907).
Datong belonged to Later Tang (923-936) during the period of the Five Dynasties and Ten Kingdoms (907-960). To enlist the help of the Khitan-ruled Liao State in his rebellion against Later Tang (923-936) and build his own kingdom, called Later Jin, Shi Jingtang, a military general, chose to be the adopted son of Emperor Taizong of Liao and ceded 16 prefectures with huge strategic importance to him in 936. Since then, Datong was under the control of Khitan, Jurchen and Mongolian people respectively for over four centuries, making the central plain of Han people vulnerable to military invasion by northern nomads.
Yuzhou Prefecture was under military attack of Liao in 937.
The Northern Song Dynasty (960-1127) divided the areas under its administration into 15 provinces. It set up an administrative region of Yunzhongfu in 1123 and launched a military campaign to recover territory lost by Later Jin with a goal of governing Yunzhong and neighboring areas.
Emperor Zonghan of the Jin Dynasty (1115-1234) conquered Datong in 1122, made the region as his western capital, and made no changes to its boundary. Datong thrived to become an important transportation hub for Han people in the central plain and ethnic minorities in northern China during the period of the Liao and Jin dynasties.
Datong was also the western capital of the Yuan Dynasty (1271-1368). The county of Yunzhong was added to its administration in 1265.
Genghis Khan (1162-1227), the great Mongol ruler, launched military invasions against Datong three times and caused huge damage to the city. Datong later grew into a magnificent and beautiful place, which was known for its commerce and production of weapons and other military supplies, as noted by Italian merchant and adventurer Marco Polo who passed through on his way to Southeast Asia under the instruction of Emperor Kublai Khan of the Yuan Dynasty in 1277.
Rulers of the Ming Dynasty (1368-1644) made consistent efforts to fortify the walls of Datong to defend against military invasions by the Mongolian and Jurchen people (ancestors of the Manchu ethnic group). Therefore, its rise to an ancient township was due to its military importance and architecture.
Datong fell into the hands of the Qing Dynasty (1644-1911) when Jiang Xiang, a general with the army led by peasant rebel leader Li Zicheng, killed his superior and surrendered himself to Qing military force in May 1645. Rulers of Qing initially followed the administrative practice of their predecessors in Ming in the governance of Datong and its neighboring areas, though later they made slight changes to its governing body. Jiang rebelled against Qing in 1648. A year later, rulers of Qing sent a heavy army to reclaim Datong. Jiang was defeated and the city was again conquered by the Qing army after a nine-month siege. Qing soldiers slaughtered local residents and partially destroyed the wall of Datong as a way to punish the rebellion. In addition, the headquarters of local government was moved to neighboring Huairen county, while Datong became only a military strongpoint. However, Datong began to thrive again when local government came back in 1652.
Datong was relegated from a provincial-level administrative region to a county during the Republic of China period (1912-49).
There were three "governments" in Datong and they were supported by different military forces with competing interests during the Chinese People's War of Resistance against Japanese Aggression (1931-45). The Japanese army entered Datong on Sept 13, 1937 and set up a puppet government a month later. The region under the control of Kuomintang forces included 13 counties such as Lingqiu, Huairen, Yanggao and Shuoxian. Meanwhile, an army led by the Communist Party of China (CPC) established a presence in Datong at the end of 1937. Areas under its control covered Lingqiu, Fanshi, Guangling, Hunyuan and Yingshan counties, together with a section of land in the west of Datong.
Datong was again under the control of Kuomintang forces, led by Yan Xishan (1883-1960), when the Japanese invaders were defeated in August 1945. It still belonged to Shanxi province and governed five prefectures with 86 villages in total. It became home to governments-in-exile of 13 counties from the region of Yanbei in 1948. Moreover, there were 22 government agencies, seven Kuomintang-related bodies and 11 organizations for secret service in the city.
An army led by the CPC peacefully entered Datong on May 1, 1949. The newly founded Central Government of the People's Republic of China later decided to elevate Datong into a municipal region under the administration of Chahar province. The city was given back to Shanxi when Chahar was removed from the list of provincial regions in China in December 1952.
Datong was under the leadership of the so-called Jinbei Special Region when the areas of Yanbei and Xinxian were allocated to form the special region in January 1959. It belonged to Yanbei Special Region again when Jinbei Special Region was canceled in July 1961. Four months later, Datong was put directly under the Shanxi Provincial People's Government after a break of nearly a decade. Datong belonged to the Yanbei Special Region again from April 1970 to March 1972.
The special region of Yanbei was abolished and its former counties were divided between Datong and the recently founded city of Shuozhou in July 1993. Since then, Datong consisted of seven counties, which were Tianzhen, Yanggao, Guangling, Lingqiu, Hunyuan, Zuoyun and Datong, together with four districts, until it underwent another reshuffle in the formation of its county-level regions in 2018.
With the approval of the State Council, the Shanxi Provincial People's Government in that year gave the nod to Datong's application to cancel the Chengqu, Southern Suburb and Coal Mine districts as well as the county of Datong in exchange for the establishment of Pingcheng, Yungang and Yunzhou districts. Today, the city is composed of Pingcheng, Yungang, Xinrong and Yunzhou districts, together with six counties.