Extracellular capsules constitute the outermost layer of many bacteria, are major virulence factors, and affect antimicrobial therapies. They have been used as epidemiological markers and recently became vaccination targets. Despite the efforts to biochemically serotype capsules in a few model pathogens, little is known of their taxonomic and environmental distribution. We developed, validated, and made available a computational tool, CapsuleFinder, to identify capsules in genomes. The analysis of over 2500 prokaryotic genomes, accessible in a database, revealed that ca. 50% of them-including Archaea-encode a capsule. The Wzx/Wzy-dependent capsular group was by far the most abundant. Surprisingly, a fifth of the genomes encode more than one capsule system-often from different groups-and their non-random co-occurrence suggests the existence of negative and positive epistatic interactions. To understand the role of multiple capsules, we queried more than 6700 metagenomes for the presence of species encoding capsules and showed that their distribution varied between environmental categories and, within the human microbiome, between body locations. Species encoding capsules, and especially those encoding multiple capsules, had larger environmental breadths than the other species. Accordingly, capsules were more frequent in environmental bacteria than in pathogens and, within the latter, they were more frequent among facultative pathogens. Nevertheless, capsules were frequent in clinical samples, and were usually associated with fast-growing bacteria with high infectious doses. Our results suggest that capsules increase the environmental range of bacteria and make them more resilient to environmental perturbations. Capsules might allow opportunistic pathogens to profit from empty ecological niches or environmental perturbations, such as those resulting from antibiotic therapy, to colonize the host. Capsule-associated virulence might thus be a by-product of environmental adaptation. Understanding the role of capsules in natural environments might enlighten their function in pathogenesis.