As a new production factor, digitalization plays a vital role in society, economy, and the environment. Based on the expanded STIRPAT model, this paper empirically tests the impact of energy structure and digital economy on carbon emissions by panel data from 2011 to 2017 in 30 provinces of China. The results show that the energy structure mainly based on coal has a significant driving effect on carbon emissions. Compared with non-resource-based provinces, the increase of energy structure dominated by coal has a greater effect on carbon emission in resource-based provinces. It is worth noting that this kind of influence has a greater impact on the central region of China, followed by the western region and the eastern region. Besides, the digital economy has a significant moderating effect. With the development of digital economy, the impact of coal-based energy structure on carbon emissions is gradually decreasing. This effect is more significant in non-resource-based provinces and eastern China, but not significant in resource-based cities and central and western China.