14Humans and other animals can identify objects by active touch, requiring the coordination of exploratory 15 motion and tactile sensation. The brain integrates movements with the resulting tactile signals to form a 16 holistic representation of object identity. We developed a shape discrimination task that challenged head-17 fixed mice to discriminate concave from convex shapes. Behavioral decoding revealed that mice did this 18 by comparing contacts across whiskers. In contrast, mice performing a shape detection task simply 19 summed up contacts over whiskers. We recorded populations of neurons in the barrel cortex, which 20 processes whisker input, to identify how it encoded the corresponding sensorimotor variables. Neurons 21 across the cortical layers encoded touch, whisker motion, and task-related signals. Sensory 22 representations were task-specific: during shape discrimination, neurons responded most robustly to 23 behaviorally relevant whiskers, overriding somatotopy. We suggest a similar dynamic modulation may 24