$ cpf --generate --validate
Valid CPF and CNPJ Generator for Testing — with Validator and Lookup
Generate mathematically valid documents — including the new alphanumeric CNPJ introduced in 2026 —, validate any number with the maths explained step by step, and look up real companies in the Receita Federal public database.
- 100% in the browser
- free
- no sign-up
The generated documents show up here. Pick the options above and click “Generate”.
The result and the step-by-step explanation of the maths show up here.
Type a CNPJ and click “Look up CNPJ”. Nothing is fetched automatically.
Source: public Receita Federal data, served by BrasilAPI (a free, open-source project). The lookup runs straight from your browser — nothing goes through CodeCrush’s servers.
How to use the CPF and CNPJ generator
On the Generate tab, pick between CPF, numeric CNPJ or the new alphanumeric CNPJ, set how many you want (from 1 to 1000) and whether the output comes formatted or as plain digits. For CPF you can even choose the state: the 9th digit encodes the Receita Federal tax region that issued it, so a CPF “from São Paulo” always carries an 8 in that position. The full test-record mode goes beyond the document and assembles fictional Brazilian records with name, email, phone, postal code and date of birth — ideal for seeding a development database. Any result can be copied or exported as JSON, CSV or SQL INSERT statements with the table name of your choice.
A “valid” CPF or CNPJ here means only that the check digits satisfy the Modulo 11 algorithm — the same verification that forms and back-office systems run before accepting a document. The Validate tab opens that black box: using the digits of your own input, it shows every multiplication by weight, the sum, the remainder of the division by 11 and the expected digit. It is the fastest way to understand why a number passes or fails validation.
The alphanumeric CNPJ: what changes in 2026
Since July 2026 the Receita Federal issues alphanumeric CNPJs (Technical Note 49/2024): the first 12 positions accept letters as well as digits, as in 12.ABC.345/01DE-35, and only the two check digits remain numeric. Systems that validate CNPJ with a digits-only regex will reject legitimate documents — which is why this generator highlights the new format, so you can test your sign-up flow, your API and your database before a real customer shows up with a CNPJ containing letters.
Common use cases
- Testing sign-up form validation in development and QA;
- Seeding staging databases with realistic fixtures (via the SQL export);
- Writing automated tests that need valid, varied documents;
- Preparing legacy systems for the 2026 alphanumeric CNPJ;
- Checking a supplier's registration status and ownership by CNPJ.
A reminder: the generated documents are fictional and exist solely for software testing. The CNPJ lookup uses public Receita Federal data served by BrasilAPI, an open-source project maintained by the Brazilian community — and everything runs in your browser, without sending anything to CodeCrush servers.
## faq
Frequently asked questions
Do the generated CPF and CNPJ numbers belong to real people or companies?
No. The generator creates random numbers that merely satisfy the mathematical check-digit rule (Modulo 11). They are not looked up in, nor registered with, any database of the Receita Federal (the Brazilian federal revenue service), so they belong to no one. A coincidence with a real document is possible, but the number itself carries no personal data.
Is it legal to use a CPF or CNPJ generator?
Yes, when used for software testing, form validation, populating development databases and demos. What is a crime is using fake documents for fraud, opening accounts in real services or impersonating someone — conduct defined in articles 171 (fraud) and 299 (false representation) of the Brazilian Penal Code.
What is the 2026 alphanumeric CNPJ?
It is the new CNPJ format defined by Joint Technical Note COCAD/SUARA/RFB No. 49/2024, issued by the Receita Federal starting July 2026. The first 12 positions now accept letters and digits (for example 12.ABC.345/01DE-35), while the two check digits remain numeric. In the calculation, each letter is worth its ASCII code minus 48 (A=17, B=18, up to Z=42).
How does the CPF check digit work?
The first 9 digits are multiplied by weights 10 down to 2, the products are added up and the sum is divided by 11. If the remainder is less than 2, the first check digit is 0; otherwise, it is 11 minus the remainder. The second digit repeats the process including the first check digit, with weights 11 down to 2. The Validate tab of this tool shows that calculation step by step with the number you type in.
Where does the CNPJ lookup data come from?
From BrasilAPI (brasilapi.com.br), a free open source project that serves public data from the Receita Federal CNPJ registry. The lookup goes straight from your browser to BrasilAPI, with no API key and without passing through CodeCrush servers.
Can I generate complete test data, beyond the document?
Yes. The complete test data mode generates fictitious Brazilian records with name, e-mail, phone, postal code (CEP) and date of birth alongside the CPF, using the Faker library with the pt-BR locale. The result can be copied or exported as JSON, CSV and SQL INSERT with a configurable table name.
What does the ninth digit of the CPF mean?
The ninth position of the CPF (the digit before the two check digits) identifies the Receita Federal fiscal region where the document was issued. There are ten regions: for example, 8 corresponds to São Paulo, 7 to Rio de Janeiro and Espírito Santo, and 6 to Minas Gerais, Bahia and other states. That is why the generator lets you pick the state (UF): it fixes the correct digit in that position to produce a CPF consistent with the desired state.
What is the difference between a valid CPF and an existing CPF?
A valid CPF is just a number whose check digits satisfy the Modulo 11 calculation — that is what this generator creates and what most forms check. An existing CPF is a number actually registered and active in the Receita Federal database, tied to a real person. The documents generated here are valid but not existing: they are meant for software testing, never for use in real services.
## other tools