Cell-mediated immunity critically depends on the localization of lymphocytes at sites of infection. While some memory T cells recirculate, a distinct lineage (resident memory T cells (T RM cells)) are embedded in nonlymphoid tissues (NLTs) and mediate potent protective immunity. However, the defining transcriptional basis for the establishment of T RM cells is unknown. We found that CD8 + T RM cells lacked expression of the transcription factor KLF2 and its target gene S1pr1 (which encodes S1P 1, a receptor for sphingosine 1-phosphate). Forced expression of S1P 1 prevented the establishment of T RM cells. Cytokines that induced a T RM cell phenotype (including transforming growth factor-β (TGF-β), interleukin 33 (IL-33) and tumor-necrosis factor) elicited downregulation of KLF2 expression in a pathway dependent on phosphatidylinositol-3-OH kinase (PI(3)K) and the kinase Akt, which suggested environmental regulation. Hence, regulation of KLF2 and S1P 1 provides a switch that dictates whether CD8 + T cells commit to recirculating or tissue-resident memory populations.