What a CPF and CNPJ generator is for
Developers and testers need CPF and CNPJ numbers that pass validation to test forms, sign-ups and integrations without using real people's data. This tool generates fictitious numbers with the correct check digits and also validates numbers you type in. The CPF (Cadastro de Pessoas FĂsicas) is the Brazilian individual taxpayer registry number, and the CNPJ (Cadastro Nacional da Pessoa JurĂdica) is the national registry number for companies.
Use it only in test environments. Generating documents to defraud registrations is a crime.
How the CPF check digit is calculated
A CPF has 9 base digits and 2 check digits. For the first one, multiply the 9 digits by weights from 10 down to 2, add them up, multiply by 10 and take the remainder of the division by 11 (if it is 10, the digit is 0). For the second one, repeat the process with the 10 digits and weights from 11 down to 2.
How the CNPJ check digit is calculated
A CNPJ has 12 base characters (8 for the root and 4 for the branch, e.g. 0001) and 2 check digits. The weights are 5,4,3,2,9,8,7,6,5,4,3,2 for the first digit and 6,5,4,3,2,9,8,7,6,5,4,3,2 for the second. If the remainder of the division by 11 is less than 2, the digit is 0; otherwise, it is 11 minus the remainder.
Alphanumeric CNPJ
Starting in July 2026, new CNPJs may contain letters as well as numbers in the first 12 positions. The check digits are calculated the same way, using the ASCII value of the character minus 48 (A = 17, B = 18 and so on). The “Alphanumeric CNPJ” option generates numbers in this format.
CPF structure
A CPF has 11 digits in the format XXX.XXX.XXX-DD: the first 8 are the base number, the 9th digit indicates the fiscal region where the record originated, and the last 2 are the check digits.
| 9th digit | Fiscal region |
|---|---|
| 0 | Rio Grande do Sul |
| 1 | Federal District, Goiás, Mato Grosso do Sul, Mato Grosso and Tocantins |
| 2 | Amazonas, Pará, Roraima, Amapá, Acre and Rondônia |
| 3 | Ceará, Maranhão and Piauà |
| 4 | ParaĂba, Pernambuco, Alagoas and Rio Grande do Norte |
| 5 | Bahia and Sergipe |
| 6 | Minas Gerais |
| 7 | Rio de Janeiro and EspĂrito Santo |
| 8 | SĂŁo Paulo |
| 9 | Paraná and Santa Catarina |
The generator draws the base number without choosing a region: the 9th digit is random.
CNPJ structure
A CNPJ has 14 positions in the format XX.XXX.XXX/XXXX-DD: 8 for the root (the company), 4 for the order number (the establishment; 0001 is the head office) and 2 check digits. In the alphanumeric CNPJ, the first 12 positions can hold letters and numbers, and the last 2 digits remain numeric.
CPF validation example in code
The algorithm used by this page's validator, in JavaScript:
function cpfValido(cpf) {
const n = cpf.replace(/\D/g, '');
if (n.length !== 11 || /^(\d)\1{10}$/.test(n)) return false;
const dv = (base) => {
let soma = 0;
for (let i = 0; i < base.length; i++) soma += Number(base[i]) * (base.length + 1 - i);
const r = (soma * 10) % 11;
return r === 10 ? 0 : r;
};
return dv(n.slice(0, 9)) === Number(n[9]) && dv(n.slice(0, 10)) === Number(n[10]);
}
For example, cpfValido('529.982.247-25') returns true. Validate on the server as well, not only in the browser.
Best practices when testing with generated documents
- Never in production: use the numbers only in test and staging environments.
- Fictitious data: the CPF is personal data protected by the LGPD (Brazil's General Data Protection Law); generating numbers avoids using real people's data in test databases.
- Store without the mask: keep only the digits and apply the mask when displaying.
- Test the limits: include invalid cases, such as repeated sequences (
111.111.111-11) and a wrong check digit.
Other tools for developers
Need passwords for your test users? Use the password generator. To set up environment variables, there is the Env Converter, and for a quick calculation, the online calculator.
Frequently asked questions
Do the generated numbers belong to real people?
No. They are random sequences that merely pass the check-digit calculation. They may coincide by chance with a real document, so use them for testing only.
Can I use them to create accounts on websites?
No. The tool is meant for software testing. Using fake documents for real registrations may constitute a crime.
How do I validate a CPF or CNPJ?
Type the number in the validation field. The tool checks the check digits, with or without punctuation, and tells you whether the number is valid. It does not query the Receita Federal (Brazil's federal tax authority).
Why are CPFs such as 111.111.111-11 invalid?
Sequences where all digits are the same pass the calculation but are rejected by rule. The tool treats them as invalid.
Is anything sent to servers?
No. Generation and validation happen in your browser.
What is the difference between numeric and alphanumeric CNPJ?
The alphanumeric CNPJ accepts letters and numbers in the first 12 positions (root and order number), while the 2 check digits remain numeric. The digits are calculated the same way, using the ASCII value of the character minus 48.
What does the 9th digit of the CPF mean?
It indicates the fiscal region where the CPF was issued, such as 8 for SĂŁo Paulo and 6 for Minas Gerais. It does not indicate the person's current state of residence, and this page's generator draws that digit at random.