The genetic code, initially thought to be universal and immutable, is now known to contain many variations, including biased codon usage, codon reassignment, ambiguous decoding and recoding. As a result of recent advances in the areas of genome sequencing, biochemistry, bioinformatics and structural biology, our understanding of genetic code flexibility has advanced substantially in the past decade. In this Review, we highlight the prevalence, evolution and mechanistic basis of genetic code variations in microorganisms, and we discuss how this flexibility of the genetic code affects microbial physiology.