Cells digest portions of their interiors in a process known as autophagy to recycle nutrients, remodel and dispose of unwanted cytoplasmic constituents. This ancient pathway, conserved from yeast to humans, is now emerging as a central player in the immunological control of bacterial, parasitic and viral infections. The process of autophagy may degrade intracellular pathogens, deliver endogenous antigens to MHC-class-II-loading compartments, direct viral nucleic acids to Toll-like receptors and regulate T-cell homeostasis. This Review describes the mechanisms of autophagy and highlights recent advances relevant to the role of autophagy in innate and adaptive immunity.