The rapid encoding of contextual memory requires the CA3 region of the hippocampus, but the necessary genetic pathways remain unclear. We found that the activity-dependent transcription factor Npas4 regulates a transcriptional program in CA3 that is required for contextual memory formation. Npas4 was specifically expressed in CA3 after contextual learning. Global knockout or selective deletion of Npas4 in CA3 both resulted in impaired contextual memory, and restoration of Npas4 in CA3 was sufficient to reverse the deficit in global knockout mice. By recruiting RNA polymerase II to promoters and enhancers of target genes, Npas4 regulates a learning-specific transcriptional program in CA3 that includes many well-known activity-regulated genes, which suggests that Npas4 is a master regulator of activity-regulated gene programs and is central to memory formation.