The Silk Road is one of the most important cultural heritage corridors connecting China and the West. A large number of grottoes have been formed along the Silk Road, which provides a solid foundation to study the spread and development of Buddhist culture. Here, a geographic information system is used to systematically analyse the spatial distribution characteristics and spatiotemporal evolution of the grottoes in Gansu Province from the Wei and Jin Dynasties to the Ming and Qing Dynasties. Additionally, the main factors affecting their distribution are discussed. Based on the distribution characteristics, the grottoes in Gansu Province are clustered and unevenly distributed, thus forming the primary gathering area in Qingyang–Tianshui city, and the secondary gathering area is dominated by Wuwei and Zhangye cities. Furthermore, the spatiotemporal characteristics show that the number and central location of the excavations and repair of the grottoes in Gansu Province have changed significantly over the past dynasties. The number of grottoes during the Northern and Southern Dynasties, the Sui and Tang Dynasties, and the Ming and Qing Dynasties was large, and the number of grottoes during the Wei, Jin and Yuan Dynasties was small. The overall trajectory of the central location shifted from northwest to southeast. Natural factors, such as topography, lithology and hydrology, as well as human factors, such as politics and transportation, have an important impact on the spatial pattern of grottoes in Gansu Province. These results provide a useful reference for the theoretical research and practical management of Buddhist cultural heritage.