Humans are adept at distinguishing between stimuli that are very similar, an ability that is particularly crucial when the outcome is of serious consequence (e.g., for a surgeon or air-traffic controller). Traditionally, selective attention was thought to facilitate perception by increasing the gain of sensory neurons tuned to the defining features of a behaviorally relevant object (e.g., color, orientation, etc.). In contrast, recent mathematical models counterintuitively suggest that, in many cases, attentional gain should be applied to neurons that are tuned away from relevant features, especially when discriminating highly similar stimuli. Here we used psychophysical methods to critically evaluate these "ideal observer" models. The data demonstrate that attention enhances the gain of the most informative sensory neurons, even when these neurons are tuned away from the behaviorally relevant target feature. Moreover, the degree to which an individual adopted optimal attentional gain settings by the end of testing predicted success rates on a difficult visual discrimination task, as well as the amount of task improvement that occurred across repeated testing sessions (learning). Contrary to most traditional accounts, these observations suggest that the primary function of attentional gain is not to enhance the representation of target features per se, but instead to optimize performance on the current perceptual task. Additionally, individual differences in gain suggest that the operating characteristics of low-level attentional phenomena are not stable trait-like attributes and that variability in how attention is deployed may play an important role in determining perceptual abilities.