Neocortical activity can evoke sensory percepts, but the cellular mechanisms remain poorly understood. We trained mice to detect single brief whisker stimuli and report perceived stimuli by licking to obtain a reward. Pharmacological inactivation and optogenetic stimulation demonstrated a causal role for the primary somatosensory barrel cortex. Whole-cell recordings from barrel cortex neurons revealed membrane potential correlates of sensory perception. Sensory responses depended strongly on prestimulus cortical state, but both slow-wave and desynchronized cortical states were compatible with task performance. Whisker deflection evoked an early (