Ai et al. report that endogenous formaldehyde bidirectionally modulates cognition via the NMDA-R receptor, with both insufficiency and overabundance resulting in cognitive defects. The target site of formaldehyde enhancing NMDA-currents is cysteine C232 residue in amino terminal domain sequence of the NR2B subunit of NMDA-R and excessive formaldehyde suppresses NMDA-R activity by cross-linking NR1 to NR2B residues.