Within species, individuals with different sexes, morphs and age classes often show spatial segregation. Both habitat selection and social processes have been proposed to explain intraspecific spatial segregation, but their relative importance is difficult to assess. We investigated spatial segregation between age classes in the cave salamander Hydromantes (Speleomantes) strinatii, and used a hypothetico‐deductive approach to evaluate whether social or ecological processes explain segregation pattern. We recorded the location and age class of salamanders along multiple caves; we measured multiple microhabitat features of different sectors of caves that may determine salamander distribution. We assessed age‐class segregation, and used generalized mixed models and an information‐theoretic framework, to test if segregation is explained by social processes or by differences in habitat selection. We found significant age‐class segregation, juveniles living in more external cave sectors than adults. Multiple environmental features varied along caves. Juveniles and adults showed contrasting habitat selection patterns: juveniles were associated with sectors having high invertebrate abundance, while adults were associated with scarce invertebrates and low temperature. When the effect of environmental features was taken into account, the relationship between juveniles and adults was non negative. This suggests that different habitat preferences, related to distinct risk‐taking strategies of age classes, can explain the spatial segregation. Juveniles require more food and select more external sectors, even if they may be risky. Conversely, adults may trade off food availability in favour of safe areas with stable micro‐climate.