The town was founded as Pingcheng in 200 BC during the Han Dynasty. Located near the Great Wall Pass to Inner Mongolia it blossomed during the following period 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 Dynasty. Pingcheng became the capital of Northern Wei from 398 AD until 494 AD. The famous Yungang Grottoes were constructed during the later part of this period (460 - 494 AD). The city was renamed Datong in 1048 AD and sacked again at the end of the Ming Dynasty (1649 AD), but promptly rebuilt in 1652 AD.