Soil salinization adversely affects soil fertility and plant growth in arid region worldwide. However, as the drivers of nutrient cycling, the response of microbial communities to soil salinization is poorly understood. This study characterized bacterial communities in different soil layers along a natural salinity gradient in the Karayulgun River Basin, located northwest of the Taklimakan desert in China, using the 16S rRNA Miseq-sequencing technique. The results revealed a significant filtering effect of salinity on the bacterial community in the topsoil. Only the α-diversity (Shannon index) in the topsoil (0–10 cm) significantly decreased with increasing salinity levels, and community dissimilarity in the topsoil was enhanced with increasing salinity, while there was no significant relationship in the subsoil. BugBase predictions revealed that aerobic, facultatively anaerobic, gram-positive, and stress-tolerant bacterial phenotypes in the topsoil was negatively related to salinity. The average degree and number of modules of the bacterial co-occurrence network in the topsoil were lower under higher salinity levels, which contrasted with the trends in the subsoil, suggesting an unstable bacterial network in the topsoil caused by higher salinity. The average path length among bacterial species increased in both soil layers under high salinity conditions. Plant diversity and available nitrogen were the main drivers affecting community composition in the topsoil, while available potassium largely shaped community composition in the subsoil. This study provides solid evidence that bacterial communities adapt to salinity through the adjustment of microbial composition based on soil depth. This information will contribute to the sustainable management of drylands and improved predictions and responses to changes in ecosystems caused by climate change.