Cognitive flexibility refers to the ability to adapt flexibly to changing circumstances. In laboratory mice, we investigated whether cognitive flexibility is higher in pubertal mice than in adult mice, and whether this difference is related to the expression of distinct NMDA receptor subunits. Using the attentional set shifting task as a measure of cognitive flexibility, we found that cognitive flexibility was increased during puberty. This difference was more pronounced in female pubertal mice. Further, the GluN2A subunit of the NMDA receptor was more expressed during puberty than after puberty. Pharmacological blockade of GluN2A reduced the cognitive flexibility of pubertal mice to adult levels. In adult mice, the expression of GluN2A, GluN2B, and GluN2C in the orbitofrontal cortex correlated positively with performance in the attentional set shifting task, whereas in pubertal mice this was only the case for GluN2C. In conclusion, the present study confirms the observation in humans that cognitive flexibility is higher during puberty than in adulthood. Future studies should investigate whether NMDA receptor subunit-specific agonists are able to rescue deficient cognitive flexibility, and whether they have the potential to be used in human diseases with deficits in cognitive flexibility.