Microbial life has dominated Earth’s history but left a sparse fossil record, greatly hindering our understanding of evolution in deep time. However, bacterial metabolism has left signatures in the geochemical record, most conspicuously the Great Oxidation Event (GOE). We combine machine learning and phylogenetic reconciliation to infer ancestral bacterial transitions to aerobic lifestyles, linking them to the GOE to calibrate the bacterial time tree. Extant bacterial phyla trace their diversity to the Archaean and Proterozoic, and bacterial families prior to the Phanerozoic. We infer that most bacterial phyla were ancestrally anaerobic and adopted aerobic lifestyles after the GOE. However, in the cyanobacterial ancestor, aerobic metabolism likely predated the GOE, which may have facilitated the evolution of oxygenic photosynthesis.