Most bacteria encode proteins for defence against infection by bacteriophages. The mechanisms that bring about phage defence are extremely diverse, suggesting frequent independent evolution of novel processes. Phage defence determinants are often plasmid or phage-encoded and many that are chromosomal show evidence of lateral transfer. Recent studies on restriction-modification (R-M) systems show that these genes are amongst the most rapidly evolving. Some bacteria have contingency genes that encode alternative target specificity determinants for Type I or Type III R-M systems, thus expanding the range of phages against which the host population is immune. The most counter-intuitive observation, however, is the prevalence of phase variation in many restriction systems, but recent arguments suggest that switching off expression of R-M systems can aid phage defence.