Diversity patterns and community assembly of soil microorganisms are essential for understanding soil biodiversity and ecosystem processes. Investigating the impacts of environmental factors on microbial community assembly is crucial for comprehending the functions of microbial biodiversity and ecosystem processes. However, these issues remain insufficiently investigated in related studies despite their fundamental significance. The present study aimed to assess the diversity and assembly of soil bacterial and fungal communities to altitude and soil depth variations in mountain ecosystems by using 16S and ITS rRNA gene sequence analyses. In addition, the major roles of environmental factors in determining soil microbial communities and assembly processes were further investigated. The results showed a U-shaped pattern of the soil bacterial diversity at 0–10  cm soil depth along altitudes, reaching a minimum value at 1800 m, while the fungal diversity exhibited a monotonically decreasing trend with increasing altitude. At 10–20  cm soil depth, the soil bacterial diversity showed no apparent changes along altitudinal gradients, while the fungal Chao1 and phylogenetic diversity (PD) indices exhibited hump-shaped patterns with increasing altitude, reaching a maximum value at 1200 m. Soil bacterial and fungal communities were distinctively distributed with altitude at the same depth of soil, and the spatial turnover rates in fungi was greater than in bacteria. Mantel tests suggested soil physiochemical and climate variables significantly correlated with the β diversity of microbial community at two soil depths, suggesting both soil and climate heterogeneity contributed to the variation of bacterial and fungal community. Correspondingly, a novel phylogenetic null model analysis demonstrated that the community assembly of soil bacterial and fungal communities were dominated by deterministic and stochastic processes, respectively. The assembly processes of bacterial community were significantly related to the soil DOC and C:N ratio, while the fungal community assembly processes were significantly related to the soil C:N ratio. Our results provide a new perspective to assess the responses of soil microbial communities to variations with altitude and soil depth.