1. Since parasite transmission is often density-dependent, group living is normally thought to lead to an increased exposure to parasitism. As a consequence, it is predicted that animals living in groups will invest more resources (energy, time, risk, etc.) in parasite defence than those living solitarily. 2. We tested this prediction by measuring basal immune parameters in the larvae of 12 species of Lepidoptera, grouped into six phylogenetically matched species-pairs, each comprising one solitary feeding and one gregariously feeding species. 3. Contrary to expectation, the solitary species in all six species-pairs had higher total haemocyte counts than the gregarious species, and in five out of six species-pairs the solitary species also exhibited higher phenoloxidase activity. Both measurements were positively correlated with each other and with the magnitude of the cellular encapsulation response. 4. The relationship between infection risk and group living was investigated with a dynamic, spatially explicit, host–pathogen model. This shows that when individuals aggregate in groups, the per capita risk of infection can be reduced if the lower between-group transmission more than compensates for the higher within-group transmission. 5. We conclude that the expectation that group living always leads to increased exposure to pathogens and parasites is overly simplistic, and that the specific details of the social system in question will determine if there is increased or decreased exposure to infection.