In terms of both phenotype and function, macrophages have remarkable heterogeneity, which reflects the specialization of tissue-resident macrophages in microenvironments as different as liver, brain and bone. Also, marked changes in the activity and gene expression programmes of macrophages can occur when they come into contact with invading microorganisms or injured tissues. Therefore, the macrophage lineage includes a remarkable diversity of cells with different functions and functional states that are specified by a complex interplay between microenvironmental signals and a hardwired differentiation programme that determines macrophage identity. In this Review, we summarize the current knowledge of transcriptional and chromatin-mediated control of macrophage polarization in physiology and disease.