CNPJ Generator & Validator - Brazilian Business ID Tool
Generate valid Brazilian CNPJ test numbers and check whether a CNPJ passes the official check-digit formula used by Brazil's Receita Federal tax authority.
Brazilian CNPJ Generator and Validator
CNPJ Generator
Generate a valid Brazilian CNPJ number for testing purposes.
CNPJ Validator
Check if a Brazilian CNPJ number is valid.
Documentation
What is a CNPJ?
CNPJ stands for Cadastro Nacional da Pessoa Jurídica. It is the identification number Brazil assigns to every registered business and other legal entity, similar to an EIN in the United States or a company registration number in the United Kingdom. A CNPJ has 14 characters, and the last two are check digits calculated from the first twelve. This tool generates numbers that pass that calculation, for use in software testing, and checks whether a given CNPJ is mathematically valid. It handles both the classic all-number CNPJ and the newer alphanumeric CNPJ.
The Brazilian Federal Revenue Service, known as Receita Federal, issues real CNPJ numbers and keeps the official registry. A number generated by this tool is not registered with Receita Federal and does not belong to any real company. It should be used only for testing, not for tax filings, contracts, or any official purpose.
CNPJ format
A CNPJ is written as XX.XXX.XXX/YYYY-ZZ. Each part means something:
- First 8 digits: the base number assigned to the company.
- Next 4 digits: the branch number.
0001is normally the company's head office, and0002,0003, and so on mark additional branches. All branches of one company share the same first 8 digits. - Last 2 digits: the check digits, calculated from the first 12 characters.
Example: 12.345.678/0001-95.
Alphanumeric CNPJ
From July 2026, Receita Federal also assigns alphanumeric CNPJs to new registrations, while existing numeric CNPJs stay valid. In the new format the first 12 characters may be the digits 0 to 9 or the capital letters A to Z. The last 2 characters are still numeric check digits. The layout and punctuation do not change.
Example: 12.ABC.345/01DE-35.
How to calculate CNPJ check digits
Both check digits use the same rule, called modulus 11: give each character a number value, multiply it by a fixed weight, add the products, and turn the sum into a single digit.
For a digit, the value is the digit itself. For a letter, the value is its ASCII code minus 48. ASCII is the standard numbering of computer characters. This makes A = 17, B = 18, and so on up to Z = 42. For a digit, ASCII minus 48 gives the digit itself, so numeric CNPJs are checked exactly as before.
First check digit (13th digit of the CNPJ):
- Multiply the values of the first 12 characters by the weights
5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, in that order. - Add up the 12 products.
- Divide the total by 11 and keep the remainder.
- If the remainder is 0 or 1, the check digit is 0. Otherwise, the check digit is
11 − remainder.
Second check digit (14th digit of the CNPJ):
- Multiply the values of the first 13 characters (the original 12 plus the first check digit just calculated) by the weights
6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2. - Add up the 13 products.
- Divide by 11 and keep the remainder.
- If the remainder is 0 or 1, the check digit is 0. Otherwise, the check digit is
11 − remainder.
A CNPJ where all 14 digits are the same, such as 11.111.111/1111-11, is always treated as invalid. This is a convention shared by most CNPJ validators, applied before the check-digit formula, because 00.000.000/0000-00 would otherwise pass it.
Worked example
Take the base digits 1 2 3 4 5 6 7 8 0 0 0 1.
Step 1 — first check digit. Multiply each digit by its weight and add the results:
| Digit | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 0 | 0 | 0 | 1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Weight | 5 | 4 | 3 | 2 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 |
| Product | 5 | 8 | 9 | 8 | 45 | 48 | 49 | 48 | 0 | 0 | 0 | 2 |
The products add up to 222. Dividing 222 by 11 gives a remainder of 2, so the first check digit is 11 − 2 = 9.
Step 2 — second check digit. The digit string is now 1 2 3 4 5 6 7 8 0 0 0 1 9 (13 digits, including the 9 from step 1). Multiplying by the second weight set and adding gives a total of 237. Dividing 237 by 11 gives a remainder of 6, so the second check digit is 11 − 6 = 5.
The full number is 12.345.678/0001-95, which is the example used throughout this page. Changing any single digit in the base number changes at least one check digit, which is why the formula catches most typing mistakes.
Alphanumeric example
Receita Federal's check-digit manual works through the base 12ABC34501DE. The letters convert to A = 17, B = 18, C = 19, D = 20 and E = 21.
| Character | 1 | 2 | A | B | C | 3 | 4 | 5 | 0 | 1 | D | E |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Value | 1 | 2 | 17 | 18 | 19 | 3 | 4 | 5 | 0 | 1 | 20 | 21 |
| Weight | 5 | 4 | 3 | 2 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 |
| Product | 5 | 8 | 51 | 36 | 171 | 24 | 28 | 30 | 0 | 4 | 60 | 42 |
The products add up to 459. The remainder of 459 ÷ 11 is 8, so the first check digit is 11 − 8 = 3. With the 3 added, the second weighted sum is 424. The remainder of 424 ÷ 11 is 6, so the second check digit is 11 − 6 = 5. The result is 12.ABC.345/01DE-35.
How to use this tool
Generator. Click "Generate CNPJ" to produce a new random number with correct check digits. By default the number is all digits. Tick "Alphanumeric format (from July 2026)" first to get a CNPJ whose first 12 characters mix digits and letters. Click "Copy" to copy it. Each result is independent; running the generator again produces a different number.
Validator. Type or paste a CNPJ into the input field, with or without punctuation, and click "Validate". Numeric and alphanumeric CNPJs are both accepted. Lowercase letters are treated as capitals, so 12.abc.345/01de-35 is valid. The tool checks that the input has 12 digits or capital letters followed by 2 digits, is not a repeated-digit pattern, and has correct check digits.
What the validator does not check
The validator only confirms that a number is built correctly according to the check-digit formula. It cannot confirm that the number is registered with Receita Federal or that it belongs to an active company. Checking real registration status requires querying Receita Federal's own public lookup service or a licensed data provider. A number can be mathematically valid without being a real, registered CNPJ, and generated numbers from this tool fall into that category by design.
Frequently asked questions
What does CNPJ stand for? Cadastro Nacional da Pessoa Jurídica, Portuguese for National Registry of Legal Entities. It is Brazil's identification number for companies and other organizations.
How many digits does a CNPJ have? 14 characters: 8 for the company's base registration, 4 for the branch number, and 2 check digits. In a numeric CNPJ all 14 are digits. In an alphanumeric CNPJ the first 12 may also be letters, but the last 2 are always digits.
Can a CNPJ contain letters? Yes, for new registrations from July 2026. Older numeric CNPJs keep their numbers. This tool validates both formats and can generate either one.
Is a generated CNPJ safe to use? Only for testing software, filling sample databases, or learning the format. It is not registered with any authority and must not be used on tax forms, contracts, or real transactions.
What is the difference between validating and verifying a CNPJ? Validating checks the math: correct length, no banned repeated-digit pattern, and correct check digits. Verifying checks whether the number is actually registered to a real company, which requires looking it up in Receita Federal's database.
How is CNPJ different from CPF? CPF (Cadastro de Pessoas Físicas) identifies individuals and has 11 digits. CNPJ identifies businesses and other legal entities and has 14 characters. The two use different check-digit calculations.
References
- Receita Federal do Brasil. CNPJ Alfanumérico: perguntas e respostas. CNPJ alfanumérico FAQ (Portuguese) —
0001marks the head office when a CNPJ is created; alphanumeric CNPJs for new registrations from July 2026; existing numbers stay valid. - Receita Federal do Brasil and Serpro. Cálculo dos dígitos verificadores de CNPJ alfanumérico. Check-digit manual (Portuguese) — character value = ASCII code minus 48; modulus 11 with weights 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 and 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2; remainder 0 or 1 gives 0, otherwise 11 minus the remainder; worked example 12.ABC.345/01DE-35.