A core issue in microbial ecology is the need to elucidate the ecological processes and underlying mechanisms involved in microbial community assembly. However, the extent to which these mechanisms differ in importance based on traits of taxa with different niche breadth is poorly understood. Here, we used high-throughput sequencing to examine the relative importance of environmental selection and stochastic processes in shaping soil bacterial sub-communities with different niche breadth (including habitat generalists, specialists and other taxa) across elevational gradients on the subalpine slope of Mount Wutai, Northern China. Our findings suggested that the composition of soil bacterial communities differed significantly different among elevational gradients. According to the niche breadth index, 10.9% of OTUs were defined as habitat generalists (B-value >8.7) and 10.0% of OTUs were defined as habitat specialists (B-value <1.5). Generalists and specialists differed distinctly in diversity and biogeographic patterns across elevational gradients. Environmental selection (deterministic processes) and spatial factors (stochastic processes) seemed to determine the assembly and biogeography of habitat generalists. However, for specialists, deterministic processes strongly influenced the distribution, while stochastic processes were not at play. Environmental drivers for generalists and specialists differed, as did their importance. Elevation, total nitrogen and pH were the main factors determining habitat generalists, and soil water content, nitrate nitrogen and pH had the strongest impacts on specialists. Moreover, variation partitioning analysis revealed that environmental selection had a much greater impact on both generalists (17.7% of pure variance was explained) and specialists (3.6%) than spatial factors. However, generalists had a much stronger response to spatial factors (2.3%) than specialists (0.3%). More importantly, null models of β-diversity suggested that specialists deviated significantly from non-neutral assembly mechanisms (relative null deviation= 0.64–0.74) relative to generalists (0.16–0.65) (P < 0.05). These results indicate that generalists and specialists are governed by different assembly mechanisms and present distinct biogeographical patterns. The large proportion of unexplained variation in specialists (93.3%) implies that very complex assembly mechanisms exist in the assembly of specialists across elevational gradients on the subalpine slope of Mount Wutai. It is essential to understand the microbial community assembly at a more refined level, and to expand the current understanding of microbial ecological mechanisms.