Carbon dioxide is produced by many organic processes and is a convenient volatile cue for insects that are searching for blood hosts, flowers, communal nests, fruit and wildfires. Although Drosophila melanogaster feed on yeast that produce CO₂ and ethanol during fermentation, laboratory experiments suggest that walking flies avoid CO₂. Here we resolve this paradox by showing that both flying and walking Drosophila find CO₂ attractive, but only when they are in an active state associated with foraging. Their aversion to CO₂ at low-activity levels may be an adaptation to avoid parasites that seek CO₂, or to avoid succumbing to respiratory acidosis in the presence of high concentrations of CO_2 that exist in nature. In contrast to CO₂, flies are attracted to ethanol in all behavioural states, and invest twice the time searching near ethanol compared to CO₂. These behavioural differences reflect the fact that ethanol is a unique signature of yeast fermentation, whereas CO₂ is generated by many natural processes. Using genetic tools, we determined that the evolutionarily conserved ionotropic co-receptor IR25a is required for CO₂ attraction, and that the receptors necessary for CO₂ avoidance are not involved in this attraction. Our study lays the foundation for future research to determine the neural circuits that underlie both state- and odorant-dependent decision-making in Drosophila