It has generally been presumed that sensory information encoded by a nervous system should be as accurate as its biological limitations allow. However, perhaps counter intuitively, accurate representations of sensory signals do not necessarily maximize the organism's chances of survival. To test this hypothesis, we developed a unified normative framework for fitness-maximizing encoding by combining theoretical insights from neuroscience, computer science, and economics. Initially, we applied predictions of this model to neural responses from large monopolar cells (LMCs) in the blowfly retina. We found that neural codes that maximize reward expectation---and not accurate sensory representations---account for retinal LMC activity. We also conducted experiments in humans and find that early sensory areas flexibly adopt neural codes that promote fitness maximization in a retinotopically-specific manner, which impacted decision behavior. Thus, our results provide evidence that fitness-maximizing rules imposed by the environment are applied at the earliest stages of sensory processing.