A contrast ratio is not the difference between two hex numbers and not a simple average of red, green and blue. WCAG uses a defined sRGB transfer function and luminance weights before comparing the lighter and darker colors. Keeping those stages visible makes boundary results reproducible.

Expand and normalize the three channels

The shorthand #ABC expands to #AABBCC. Each two-digit channel becomes an integer from 0 through 255, then is divided by 255. This produces encoded sRGB values from 0 through 1. ContrastCheck accepts only three- or six-digit opaque hex colors, so alpha blending, CSS color names and color-space conversions cannot enter the calculation silently.

Convert encoded sRGB to linear light

For a normalized channel at or below 0.04045, divide by 12.92. Above 0.04045, add 0.055, divide by 1.055 and raise the result to 2.4. Relative luminance is then 0.2126 times linear red plus 0.7152 times green plus 0.0722 times blue. Green carries the greatest weight; equal numeric channel changes therefore need not change luminance equally.

Compare lighter and darker luminance

Let L1 be the greater luminance and L2 the smaller. The ratio is (L1 + 0.05) divided by (L2 + 0.05), so order does not change its magnitude and the range is 1:1 through 21:1. ContrastCheck evaluates thresholds with the raw value. It floors only the visible number to two decimals, avoiding a displayed 4.50 when the actual ratio is just below 4.5.