CNPJ generator and validator
The CNPJ is the national registry number of Brazilian companies, issued by Receita Federal. Generate fictitious CNPJs in the classic numeric format or the new alphanumeric one and test that your code handles both, entirely in your browser.
Up to 1000 items at once. Everything is generated in your browser.
How to use
- Choose With mask (punctuation) for
00.000.000/0000-00, or turn it off for the raw 14 characters. - Enable the alphanumeric option to get letters in the root, like the new CNPJs; when off, the root is digits only.
- Click Generate, then Copy. Samples are always head offices, with branch number
0001. - For seed data, set the Quantity (1–1000) and use Export CSV or Export JSON.
- On the Validate tab, paste one or many CNPJs, one per line, numeric or alphanumeric; each line shows valid or the reason it failed.
How it works
CNPJ structure
A CNPJ (Cadastro Nacional da Pessoa Jurídica) has 14 positions: an 8-character root identifying the company, a 4-character branch number (0001 is usually the head office) and 2 check digits.
The new alphanumeric CNPJ
Receita Federal Normative Instruction (IN RFB) No. 2,229/2024 allows the first 12 positions to contain letters A–Z as well as digits. Receita scheduled the first alphanumeric CNPJs for July 2026, for new registrations only; existing CNPJs keep their numbers. The two check digits remain numeric. For the calculation, each character is worth its ASCII code minus 48, so digits keep their value ('0' = 0 … '9' = 9) and letters go from A = 17 to Z = 42. One routine therefore validates both formats.
Check-digit algorithm
- Multiply the values of the first 12 positions by the weights 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 and add them.
- Take the remainder modulo 11: below 2 gives 0, otherwise the digit is 11 − remainder.
- For the second digit, use the 13 positions (including the first check digit) with weights 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2.
Worked example: 12.ABC.345/01DE-??
This is the example published by Receita Federal. Values: 1, 2, A=17, B=18, C=19, 3, 4, 5, 0, 1, D=20, E=21.
First digit: 1×5 + 2×4 + 17×3 + 18×2 + 19×9 + 3×8 + 4×7 + 5×6 + 0×5 + 1×4 + 20×3 + 21×2 = 5 + 8 + 51 + 36 + 171 + 24 + 28 + 30 + 0 + 4 + 60 + 42 = 459. 459 mod 11 = 8, digit = 11 − 8 = 3.
Second digit: 1×6 + 2×5 + 17×4 + 18×3 + 19×2 + 3×9 + 4×8 + 5×7 + 0×6 + 1×5 + 20×4 + 21×3 + 3×2 = 6 + 10 + 68 + 54 + 38 + 27 + 32 + 35 + 0 + 5 + 80 + 63 + 6 = 424. 424 mod 11 = 6, digit = 11 − 6 = 5.
Result: 12.ABC.345/01DE-35. A numeric CNPJ follows exactly the same steps, just without letters.
FAQ
Does my system need changes for the alphanumeric CNPJ?
Probably, if it stores CNPJs as integers, uses digit-only input masks or strips letters during validation. Store 14 characters in a text column, uppercase the input and compute check digits with ASCII − 48. Use the alphanumeric generator to build regression test cases now.
Will existing CNPJs change?
No. Under Receita Federal’s rules, numbers already issued stay valid and unchanged. The alphanumeric format applies to new registrations from July 2026, so both formats will coexist in databases and API payloads for many years.
Do the generated CNPJs belong to real companies?
They are random combinations that only satisfy the check-digit rule; the tool never queries Receita Federal. A collision with a registered company is possible, so use the numbers only in tests, demos and staging environments, never for real registrations.
Does the validator accept lowercase letters?
Yes. Input is uppercased and punctuation is ignored before the calculation. It rejects characters outside 0–9 and A–Z, lengths other than 14, repeated-character strings and letters in the check-digit positions, which are always numeric.
What does the 0001 part mean?
It is the establishment (branch) number: 0001 normally marks the head office and 0002 onward the branches sharing the same root. The validator shows it in the result. In the new format the branch part may contain letters too, as in the official example 01DE.
Sources
- Receita Federal — Alphanumeric CNPJ (Portuguese)
- Receita Federal — IN RFB No. 2,229/2024 (Portuguese)
Related tools
Updated 2026-11-13 · Rafael Lima