How the immune system remembers a previous encounter with a pathogen and responds more efficiently to a subsequent encounter has been one of the central enigmas for immunologists for over a century. The identification of pathogen-specific memory lymphocytes that arise after an infection provided a cellular basis for immunological memory. But the molecular mechanisms of immunological memory remain only partially understood. The emerging evidence suggests that epigenetic changes have a key role in controlling the distinct transcriptional profiles of memory lymphocytes and thus in shaping their function. In this Review, we summarize the recent progress that has been made in assessing the differential gene expression and chromatin modifications in memory CD4(+) and CD8(+) T cells, and we present our current understanding of the molecular basis of memory T cell function.