The aim of our study was to characterize the factors that shape the pattern of change in ant species richness and community structure along altitudinal gradients in two valleys located on the northern and southern side of the Pyrenees. During three summers, we sampled 20 sites distributed across two Pyrenean valleys ranging in elevation from 1,009 to 2,339 m using pitfall traps and hand collection. We employed diversity index, degree of nestedness of ant assemblages, ordination method, and multiple regression analysis to examine the effects of various environmental factors on ant species communities. In total, 41 ant species were found in the two valleys. The number of species was 26 % lower in the valley located on the northern side than in that located on the southern side. At the valley scale, the number of ant species, as well as the evenness, decreased with elevation. A significant nested pattern was observed, indicating that the species found in the poorest site represented a subset of those found at the richest one. Ants collected at mid- and high-elevation sites had a wider altitudinal range than those collected at low-elevation sites, thus complying with Rapoport’s rule. Our results suggest that, although elevation strongly influences the organization of ant communities, ecological factors such as temperature and local habitat features (sun exposure, vegetation density) are the main factors explaining the pattern of ant diversity along altitudinal gradients.