Nearly all animals are capable of sensing changes in environmental oxygen (O2) and carbon dioxide (CO2) levels, which can signal the presence of food, pathogens, conspecifics, predators, or hosts. The free-living nematode Caenorhabditis elegans is a powerful model system for the study of gas sensing. C. elegans detects changes in O2 and CO2 levels and integrates information about ambient gas levels with other internal and external cues to generate context-appropriate behavioral responses. Due to its small nervous system and amenability to genetic and genomic analyses, the functional properties of its gas-sensing microcircuits can be dissected with single-cell resolution, and signaling molecules and natural genetic variations that modulate gas responses can be identified. Here, we discuss the neural basis of gas sensing in C. elegans, and highlight changes in gas-evoked behaviors in the context of other sensory cues and natural genetic variations. We also discuss gas sensing in other free-living nematodes and parasitic nematodes, focusing on how gas-sensing behavior has evolved to mediate species-specific behavioral requirements.