The formula behind the number
Relative luminance is a weighted sum of the three channels after removing gamma encoding: 0.2126 red, 0.7152 green, 0.0722 blue. Green dominates because human vision is most sensitive to it, which is why a light green and a light red can have very different perceived brightness.
The contrast ratio is (L1 + 0.05) / (L2 + 0.05) where L1 is the lighter luminance. The 0.05 offset stops the ratio from going to infinity when both colors are near black. The maximum is 21:1, black on white.
What AA and AAA demand
Level AA asks for 4.5:1 for normal text and 3:1 for large text, defined as 18 point (24 pixels) or 14 point bold (18.66 pixels). Level AAA asks for 7:1 and 4.5:1 respectively. For a typical blog, AA is the realistic target; AAA is hard to hit with brand colors.
Non-text elements such as button borders and form outlines need 3:1 against their surroundings under the same rules, which is where many sites fail without noticing - the label passes but the input border does not.
The mistakes that fail audits
Placeholder text is the most common failure: grey on white usually lands near 2.5:1. Disabled states are exempt, but placeholder text is not.
The second most common is overlay text on photos. A gradient scrim under the text fixes it more reliably than picking a luckier photo, because the ratio then stays stable as images rotate.