DNA methylation is of paramount importance for mammalian embryonic development. DNA methylation has numerous functions: it is implicated in the repression of transposons and genes, but is also associated with actively transcribed gene bodies and, in some cases, with gene activation per se. In recent years, sensitive technologies have been developed that allow the interrogation of DNA methylation patterns from a small number of cells. The use of these technologies has greatly improved our knowledge of DNA methylation dynamics and heterogeneity in embryos and in specific tissues. Combined with genetic analyses, it is increasingly apparent that regulation of DNA methylation erasure and (re-)establishment varies considerably between different developmental stages. In this Review, we discuss the mechanisms and functions of DNA methylation and demethylation in both mice and humans at CpG-rich promoters, gene bodies and transposable elements. We highlight the dynamic erasure and re-establishment of DNA methylation in embryonic, germline and somatic cell development. Finally, we provide insights into DNA methylation gained from studying genetic diseases.