Bacteria and archaea have evolved sophisticated adaptive immune systems, known as CRISPR-Cas (clustered regularly interspaced short palindromic repeats-CRISPR-associated proteins) systems, which target and inactivate invading viruses and plasmids. Immunity is acquired by integrating short fragments of foreign DNA into CRISPR loci, and following transcription and processing of these loci, the CRISPR RNAs (crRNAs) guide the Cas proteins to complementary invading nucleic acid, which results in target interference. In this Review, we summarize the recent structural and biochemical insights that have been gained for the three major types of CRISPR-Cas systems, which together provide a detailed molecular understanding of the unique and conserved mechanisms of RNA-guided adaptive immunity in bacteria and archaea.