Soil pH is a critical property influencing soil health and functions, nutrient availability and microbial activities, and agricultural productivity. Interpreting machine learning models in soil science is a challenge, despite their increasing application. We used a dataset of 2651 soil samples up to 60 cm depth to understand the drivers controlling spatial and depth distribution of soil pH and related them to soil-forming factors in foothills mountains and semi-arid steppes of southern Ural (Russia). Machine learning approach allowed to analyse the effects of key soil-forming factors (climate, topography, vegetation, soil and parent materials) for the predictions and the role of covariates utilizing Shapley values, a game theory-based method to quantify the average marginal contribution of a predictor. The developed models explained 62 %, 56 % and 54 % of the pH variation in 0–20, 20–40 and 40–60 cm, respectively. Climate (precipitation, cloud cover and surface temperature), soil type and elevation were the most important factors of soil pH across all depths. When precipitation in December exceeds 30–35 mm, cloud cover 58–60 % and elevation 400–450 m, the model predicted a lower pH compared with a mean level across all depths. The generated pH maps also revealed a change in soil pH from mountainous forested ecosystems to semi-arid steppe landscapes. These findings are mainly explained by the difference in precipitation-driven leaching and evapotranspiration-induced salt accumulation in soils in the area (9,500 km2). Our study underscores the complexity and non-linearity of the relationships between pH and the environmental variables, providing valuable insights into their variations across both horizontal and vertical spatial dimensions. © 2025 Elsevier B.V., All rights reserved.