Information processing in the cerebral cortex depends not only on the nature of incoming stimuli, but also on the state of neuronal networks at the time of stimulation. That is, the same stimulus will be processed differently depending on the neuronal context in which it is received. A major factor that could influence neuronal context is the background, or ongoing neuronal activity before stimulation. In visual cortex, ongoing activity is known to play a critical role in the development of local circuits, yet whether it influences the coding of visual features in adult cortex is unclear. Here, we investigate whether and how the information encoded by individual neurons and populations in primary visual cortex (V1) depends on the ongoing activity before stimulus presentation. We report that when individual neurons are in a “low” prestimulus state, they have a higher capacity to discriminate stimulus features, such as orientation, despite their reduction in evoked responses. By measuring the distribution of prestimulus activity across a population of neurons, we found that network discrimination accuracy is improved in the low prestimulus state. Thus, the distribution of ongoing activity states across the network creates an “internal context” that dynamically filters incoming stimuli to modulate the accuracy of sensory coding. The modulation of stimulus coding by ongoing activity state is consistent with recurrent network models in which ongoing activity dynamically controls the balanced background excitation and inhibition to individual neurons.