How CPF and CNPJ check digits work
CPF (individual taxpayer number) has 9 base digits and 2 check digits, each calculated with modulo 11 and descending weights (10…2, then 11…2). A remainder below 2 gives 0, otherwise 11 − remainder. Numbers with all-equal digits (111.111.111-11) are invalid.
CNPJ (company number) has 8 base characters, a 4-character branch number (0001 is the head office) and 2 check digits with weights 5…2, 9…2 and 6…2, 9…2. Since July 2026 the Receita Federal also issues alphanumeric CNPJ: the first 12 characters may contain letters, each character counts as its ASCII code minus 48 (A = 17), and the check digits stay numeric. Existing numeric CNPJ remain valid, so systems must accept both.
QA checklist
- Accept input with and without punctuation; store digits only (and upper-case letters for CNPJ).
- Reject all-equal sequences.
- Do not make CNPJ fields numeric-only: test with an alphanumeric CNPJ like
12.ABC.345/01DE-35.
FAQ
Do these numbers belong to real people?
They are random numbers that pass the check-digit rules; one might coincide with a real registration. Use them only for testing.