Restriction–modification (R-M) systems are able to methylate or cleave DNA depending on methylation status of their recognition site. It allows them to protect bacterial cells from invasion by foreign DNA. Comparative analysis of a large number of available bacterial genomes and methylomes clearly demonstrates that the role of R-M systems in bacteria is wider than only defense. R-M systems maintain heterogeneity of a bacterial population and are involved in adaptation of bacteria to change in their environmental conditions. R-M systems can be essential for host colonization by pathogenic bacteria. Phase variation and intragenomic recombinations are sources of the fast evolution of the specificity of R-M systems. This review focuses on the influence of R-M systems on evolution and ecology of prokaryotes.