Microbial community assembly is affected by trade-offs between deterministic and stochastic processes. However, the mechanisms underlying the relative influences of the two processes remain elusive. This knowledge gap limits our ability to understand the effects of community assembly processes on microbial community structures and functions. To better understand community assembly mechanisms, the community dynamics of bacterial ecological groups were investigated based on niche breadths in 23 soil plots from subalpine coniferous forests on the Loess Plateau in Shanxi, China. Here, the overall community was divided into the ecological groups that corresponded to habitat generalists, ‘other taxa’ and specialists. Redundancy analysis based on Bray-Curtis distances (db-RDA) and multiple regression tree (MRT) analysis indicated that soil organic carbon (SOC) was a general descriptor that encompassed the environmental gradients by which the communities responded to, because it can explain more significant variations in community diversity patterns. The three ecological groups exhibited different niche optima and degrees of specialization (i.e., niche breadths) along the SOC gradient, suggesting the presence of a gradient in tolerance for environmental heterogeneity. The inferred community assembly processes varied along the SOC gradient, wherein a transition was observed from homogenizing dispersal to variable selection that reflects increasing deterministic processes. Moreover, the ecological groups were inferred to perform different community functions that varied with community composition, structure. In conclusion, these results contribute to our understanding of the trade-offs between community assembly mechanisms and the responses of community structure and function to environmental gradients.