Brazilian CPF and CNPJ: Check Digits and the Alphanumeric CNPJ
In Brazil almost every purchase, contract and invoice asks for a CPF, the taxpayer number of a person, or a CNPJ, the number of a company or other legal entity. Both end in two check digits calculated by the Receita Federal's modulo 11 rule. From July 2026 new CNPJs can also contain letters. This guide explains how both numbers are built, how to calculate the check digits with the Receita Federal's own examples, and what the alphanumeric CNPJ means for software.
Two Registers, One Rule Family
| Number | Who has one | Format | Example |
|---|---|---|---|
| CPF (Cadastro de Pessoas Físicas) | Individuals | 11 digits: 000.000.000-00 | 280.012.389-38 |
| CNPJ, numeric | Companies and other legal entities | 14 digits: 00.000.000/0000-00 | 18.781.203/0001-28 |
| CNPJ, alphanumeric | New registrations from July 2026 | 12 characters 0–9 or A–Z, then 2 digits | 12.ABC.345/01DE-35 |
All three examples come from Receita Federal documents: the CPF and the numeric CNPJ from the e-Financeira layout manual, the alphanumeric CNPJ from its note on calculating the check digits.
How the CPF Is Built
A CPF has eleven digits. The ninth digit is the fiscal region (Região Fiscal) of the address given at the first registration, and the last two are check digits. The Receita Federal lists the regions as: 1 DF, GO, MT, MS, TO; 2 PA, AM, AC, AP, RO, RR; 3 CE, MA, PI; 4 PE, RN, PB, AL; 5 BA, SE; 6 MG; 7 RJ, ES; 8 SP; 9 PR, SC; 0 RS. The region does not change when the person moves, so it says nothing about where they live now.
Check Digits of a CPF
- Multiply the first nine digits by 10, 9, 8, 7, 6, 5, 4, 3 and 2 and add the products.
- Divide the sum by 11. If the remainder is 0 or 1, the first check digit is 0; otherwise it is 11 minus the remainder.
- For the second check digit, take the first ten digits (including the one just calculated), multiply them by 11, 10, … 2 and apply the same rule.
Worked example: for 280.012.389, 2×10 + 8×9 + 0×8 + 0×7 + 1×6 + 2×5 + 3×4 + 8×3 + 9×2 = 162. 162 = 14 × 11 + 8, so the first digit is 11 − 8 = 3. Then 2×11 + 8×10 + 0×9 + 0×8 + 1×7 + 2×6 + 3×5 + 8×4 + 9×3 + 3×2 = 201 = 18 × 11 + 3, so the second digit is 11 − 3 = 8. The result is 280.012.389-38.
The Receita Federal manual words the same rule differently: weights 9, 8, … 1, 0 counted from the last digit, and a remainder of 10 counts as 0. Both versions always give the same digits.
How the CNPJ Is Built
A CNPJ has 14 positions, written AA.AAA.AAA/AAAA-DV: an 8-character root that identifies the entity, a 4-character order that identifies the establishment, and two check digits. Until now every position was a digit. According to the Receita Federal, the alphanumeric CNPJ is assigned from July 2026 to new registrations only; the root and the order may then contain capital letters A–Z, while the check digits stay numeric. Existing CNPJs keep their numbers.
Check Digits of a CNPJ, With or Without Letters
The Receita Federal publishes one calculation for both kinds of CNPJ:
- Give each of the first 12 characters its ASCII code minus 48. Digits keep their value (0–9); A = 17, B = 18 … Z = 42.
- Write the weights 2, 3, 4, 5, 6, 7, 8, 9 from right to left and start again at 2 after 9, so the 12 characters get 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2.
- Multiply, add and divide by 11. A remainder of 0 or 1 gives 0; otherwise the digit is 11 minus the remainder.
- Repeat over 13 characters (the 12 plus the first check digit) for the second digit.
Worked example: for 12.ABC.345/01DE the values are 1, 2, 17, 18, 19, 3, 4, 5, 0, 1, 20, 21. The products are 5, 8, 51, 36, 171, 24, 28, 30, 0, 4, 60 and 42, which add up to 459 = 41 × 11 + 8, so the first digit is 11 − 8 = 3. The second calculation gives 5, so the full number is 12.ABC.345/01DE-35. Because digits keep their value, a numeric CNPJ such as 18.781.203/0001-28 comes out exactly as before.
What Changes for Software
- Store CNPJs as text. A numeric column (integer or decimal) cannot hold letters and drops leading zeros. A 14-character text field holds both forms.
- Accept letters in the first 12 positions only. After removing dots, the slash and the hyphen, a valid shape is 12 characters 0–9 or A–Z followed by 2 digits.
- Normalise case. The Receita Federal uses capital letters; converting input to upper case before checking avoids false errors.
- Check validators and masks. Input masks, regular expressions and libraries that assume 14 digits reject the new numbers.
- Keep the CPF as it is. The change affects the CNPJ only; the CPF stays numeric.
What a Correct Result Does Not Prove
- Registration. Roughly one random number in a hundred passes both check digits. Whether a CPF or CNPJ is registered, and its status (situação cadastral), can only be checked with the Receita Federal.
- The right person or company. A real number copied from someone else passes every check.
- Repeated digits. 111.111.111-11 and similar numbers satisfy the arithmetic but are commonly used as placeholders; the validator warns about them.
Frequently Asked Questions
Do existing CNPJs change in 2026?
No. According to the Receita Federal, the alphanumeric CNPJ is assigned only to new registrations from July 2026, and existing numbers do not change.
Can the check digits of a CNPJ be letters?
No. The two check digits are always digits; letters may appear only in the root and the order.
Does the CPF become alphanumeric too?
No. The change announced by the Receita Federal concerns the CNPJ.
Can the validator tell me whose number it is?
No. It only calculates check digits in your browser and does not look numbers up in any register.
Sources
Source: Receita Federal: folheto «Cadastros – CPF e CNPJ» · Last checked:
Source: Receita Federal: Cálculo do DV do CNPJ Alfanumérico · Last checked:
Source: Receita Federal / Serpro: Cálculo dos dígitos verificadores de CNPJ alfanumérico · Last checked:
Source: Receita Federal: CNPJ alfanumérico – Perguntas e respostas · Last checked:
Source: Receita Federal: CNPJ Alfanumérico · Last checked: