Soil is the largest carbon reservoir in terrestrial ecosystems, and thus minor changes in it can dramatically affect atmospheric CO 2 concentrations. The fragile ecological environment in the northwestern arid zone of China is susceptible to natural and anthropogenic disturbances, which lead to variations in structure and function of the ecosystem, as well as carbon source–sink dynamics. In this study, digital soil maps of soil organic carbon stocks (SOCS) were produced at a 90-m resolution for two periods (the 1980s and 2010s) based on historical soil profile data and a random forest model. The results showed that the prediction accuracy for SOCS in the topsoil (0–30 cm) was superior to that of the subsoil (30–100 cm). Among them, the mean annual evapotranspiration, normalized difference vegetation index during the growing season, multi-year mean temperature, and clay content were the main environmental factors affecting the spatial distribution of SOCS. In the past 30 years, the SOCS of the northwestern arid zone have decreased by 585.50 Tg, with a mean decline of 19.52 Tg C yr -1. The changes in SOCS caused by land-use conversion and reductions in SOCS were further shown to be attributable to grassland desertification and agricultural reclamation. These findings are valuable for exploring the carbon cycle in terrestrial ecosystems in the context of global climate change and for achieving China’s goal of carbon neutrality.