In China, the number of senior citizens has grown, along with the burden of old age, and aging has hampered economic growth. The advent of the digital age has led to the emergence of the digital economy as a new engine for economic growth. This paper uses DEA-Malmquist index model to measure the total factor productivity growth rate of 31 provinces in China from 2011 to 2021, and uses the moderating effects model to empirically investigate the relationship between the digital economy, aging and total factor productivity, and to verify whether the development of the digital economy can mitigate the negative impact of aging on total factor productivity. The results show that aging inhibits total factor productivity growth, and the digital economy can promote total factor productivity growth. Digital economy can alleviate the negative impact of aging on total factor productivity growth, and has a moderating effect. Digital economy plays a moderating role by improving the level of human capital and facilitating technological progress. The regional heterogeneity analysis shows that the moderating effect of the digital economy exists in the eastern and western regions and the southern region, but not in the central region and the northern region. Furthermore, the digital economy has a moderating effect on both the high and low aging groups. The research in this paper not only helps to evaluate the productivity effects of the digital economy, but also has important implications for finding ways to mitigate the negative effects of aging.