The altitude distribution patterns of soil microorganisms and their driving mechanisms are crucial for understanding the consequences of climate change on terrestrial ecosystems. There is an obvious altitude difference in Datong River Basin in the Qilian Mountains. Two spatial scale transections were set up along the mountain slope (with altitude spanning 1 000 m) and the mainstream direction (with altitude spanning 300-500 m), respectively. The distribution characteristics of the soil bacterial community structure and diversity along the altitude gradients were examined using high-throughput sequencing technology. Based on the FAPROTAX database, the altitude distribution patterns of nitrogen cycling functional groups were analyzed to investigate the major environmental factors influencing the altitude distribution patterns of soil bacterial communities. The findings revealed that:① Soil physicochemical characteristics varied significantly with altitude. The content of total nitrogen (TN) and nitrate nitrogen (NO3-) were positively correlated with the altitude (P < 0.01), whereas the soil bulk density and pH were negatively connected (P < 0.001). ② The abundance of OTU increased significantly along the altitude (P < 0.01), and the richness and diversity indices increased along the altitude, although the trend was not statistically significant (P > 0.05). ③ The predominant bacterial communities were Acidobacteria, Proteobacteria, and Bacteroidetes, and as altitude climbed, their relative abundances varied between increasing, decreasing, and slightly decreasing, respectively. ④ The nitrogen cycling processes involved 13 functional groups, primarily nitrification, aerobic ammonia oxidation, aerobic nitrite oxidation, etc. As the altitude increased, the response law changed, with an increase in the abundance of nitrobacteria (P < 0.01), a slight increase in the abundance of aerobic ammonia-oxidizing bacteria and nitrite-oxidizing bacteria, and a hump-back tendency in bacteria abundance for nitrogen respiration. ⑤ Redundancy analysis revealed that the key determinants influencing soil bacterial populations at the phylum level were altitude, pH, and the content of NH4+. Mantel analysis showed that the dominant groups of soil bacterial nitrogen cycling were all statistically and significantly driven by altitude (P < 0.01). ⑥ The α-diversity of the bacterial community with increasing altitude were both increased along the mountain slope and the mainstream direction, but the soil properties, the abundance of N-cycling functional groups, and the main environmental factors differed. Therefore, it is of great significance to explore the altitude distribution pattern of soil microorganisms at different spatial scales.