Encoding and retrieval of memory are two processes serving distinct biological purposes but operating in highly overlapping brain circuits. It is unclear how the two processes are coordinated in the same brain regions, especially in the hippocampal CA1 region where the two processes converge at the cellular level. Here we find that the neuron-derived neurotrophic factor (NDNF)-positive interneurons at stratum lacunosum-moleculare (SLM) in CA1 play opposite roles in memory encoding and retrieval. These interneurons show high activities in learning and low activities in recall. Increasing their activity facilitates learning but impairs recall. They inhibit the entorhinal- but dis-inhibit the CA3- inputs to CA1 pyramidal cells and thereby either suppress or elevate CA1 pyramidal cells’ activity depending on animal’s behavioral states. Thus, by coordinating entorhinal- and CA3- dual inputs to CA1, these SLM interneurons are key to switching the hippocampus between encoding and retrieval modes.