Multiple cortical areas including the primary somatosensory cortex (S1) are activated during itch signal processing, yet cortical representation of itch perception remains unknown. Using novel miniature two-photon microscopic imaging in free-moving mice, we investigated the coding of itch perception in S1. We found that pharmacological inactivation of S1 abolished itch-induced scratching behavior, and the itch-induced scratching behavior could be well predicted by the activity of a fraction of layer 2/3 pyramidal neurons, suggesting that a subpopulation of S1 pyramidal neurons encoded itch perception, as indicated by immediate subsequent scratching behaviors. With a newly established optogenetics-based paradigm that allows precisely controlled pruritic stimulation, we found that a small fraction of S1 neurons exhibited an ignition-like pattern at the detection threshold of itch perception. Our study revealed the neural mechanism underlying itch perceptual coding in S1, thus paving the way for the study of cortical representation of itch perception at the single-neuron level in freely moving animals.