Most sensory stimuli are actively sampled, yet the role of sampling behavior in shaping sensory codes is poorly understood. Mammals sample odors by sniffing, a complex behavior that controls odorant access to receptor neurons. Whether sniffing shapes the neural code for odors remains unclear. We addressed this question by imaging receptor input to the olfactory bulb of awake rats performing odor discriminations that elicited different sniffing behaviors. High-frequency sniffing of an odorant attenuated inputs encoding that odorant, whereas lower sniff frequencies caused little attenuation. Odorants encountered later in a sniff bout were encoded as the combination of that odorant and the background odorant during low-frequency sniffing, but were encoded as the difference between the two odorants during high-frequency sniffing. Thus, sniffing controls an adaptive filter for detecting changes in the odor landscape. These data suggest an unexpected functional role for sniffing and show that sensory codes can be transformed by sampling behavior alone.