Drosophila melanogaster feed on yeast cells, which produce CO2; however, whether flies are attracted to CO2 is unclear. By manipulating the temperature and wind speed in a wind tunnel, the authors altered the activity levels of flies while recording their flight trajectories in response to plumes of CO2. More active flies were attracted to CO2, whereas less active flies found it aversive. Unlike aversion, attraction to CO2 depended on the olfactory ionotropic co-receptor IR25a. Thus, flies show state-dependent responses to CO2 through distinct pathways.