Memories are believed to be encoded by sparse ensembles of neurons in the brain. However, it remains unclear whether there is functional heterogeneity within individual memory engrams, i.e., if separate neuronal subpopulations encode distinct aspects of the memory and drive memory expression differently. Here, we show that contextual fear memory engrams in the mouse dentate gyrus contain functionally distinct neuronal ensembles, genetically defined by the Fos- or Npas4-dependent transcriptional pathways. The Fos-dependent ensemble promotes memory generalization and receives enhanced excitatory synaptic inputs from the medial entorhinal cortex, which we find itself also mediates generalization. The Npas4-dependent ensemble promotes memory discrimination and receives enhanced inhibitory drive from local cholecystokinin-expressing interneurons, the activity of which is required for discrimination. Our study provides causal evidence for functional heterogeneity within the memory engram and reveals synaptic and circuit mechanisms used by each ensemble to regulate the memory discrimination-generalization balance.