Like many organisms, bacteria and archaea have both innate and adaptive immune systems to defend against infection by viruses and other parasites. Innate immunity most commonly relies on the endonuclease-mediated cleavage of any incoming DNA that lacks a specific epigenetic modification, through a system known as restriction–modification. CRISPR–Cas-mediated adaptive immunity relies on the insertion of short DNA sequences from parasite genomes into CRISPR arrays on the host genome to provide sequence-specific protection. The discovery of each of these systems has revolutionised our ability to carry out genetic manipulations, and, as a consequence, the enzymes involved have been characterised in exquisite detail. In comparison, much less is known about the importance of these two arms of the defence for the ecology and evolution of prokaryotes and their parasites. Here, we review our current ecological and evolutionary understanding of these systems in isolation, and discuss the need to study how innate and adaptive immune responses are integrated when they coexist in the same cell.