Autophagy is a membrane trafficking pathway that results in the formation of autophagosomes which deliver portions of the cytosol to lysosomes for degradation. When autophagosomes engulf intracellular pathogens, the pathway is called 'xenophagy' because it leads to the removal of foreign material. Autophagy is activated during infection by Toll-like receptors that recognize pathogen-associated molecular patterns. This allows autophagy to kill micro-organisms and present pathogen components to the innate and acquired immune systems. The targeting of pathogens by autophagy is selective and involves a growing family of autophagy receptors that bind to the autophagosome membrane protein LC3 (light-chain 3)/Atg8 (autography-related protein 8). Ubiquitination of microbes identifies them as substrates for autophagy and they are delivered to autophagosomes by autophagy receptors that bind both ubiquitin and LC3/Atg8. Bacteria can also be detected before they enter the cytosol by autophagy receptors that scan the surface of membrane compartments for evidence of damage. The observation that some pathogens survive in cells suggests they can evade complete destruction by autophagy. For some bacteria this involves proteins that shield the surface of the bacteria from recognition by autophagy receptors. Other viruses and bacteria are resistant to degradation in lysosomes and use autophagosomes and/or lysosomes as sites for replication. Most of our current understanding of the role played by autophagy during microbial infection has come from studies of bacteria and viruses in tissue culture cell lines. Future work will focus on understanding how autophagy determines the outcome of infection 'in vivo', and how autophagy pathways can be exploited therapeutically.