Natural environments are constantly in flux causing dramatic changes in the statistics of sensory signals. In order to efficiently encode information relevant for diverse tasks, sensory systems must infer these changes and adapt to them. In this talk, I will present a theoretical framework for optimization and analysis of adaptive sensory codes which can support dynamic inference of changing stimulus distributions. Such adaptive codes enable accurate inference under strong resource constraints and differ substantially from representations optimized for stationary environments. Our framework generates a broad spectrum of experimental predictions about dynamic coding phenomena in the brain – from adaptation in retinal neurons to dynamic reorganization of population codes in the visual cortex.