๐Ÿ‡ง๐Ÿ‡ท

Free CPF & CNPJ Validator

Validate and format Brazilian CPF (personal) and CNPJ (company) tax IDs. Generate test values for development and QA. Uses the official Receita Federal check-digit algorithm.

โœ… Validates CPFโœ… Validates CNPJ๐ŸŽฒ Generates test IDs๐Ÿ”ค Auto-formats๐Ÿ†“ Completely Free

CPF โ€” Cadastro de Pessoas Fรญsicas

The Brazilian individual taxpayer registry number โ€” 11 digits formatted as 000.000.000-00. Issued by Receita Federal. Required for opening bank accounts, signing contracts, paying taxes, and most adult activities in Brazil.

CNPJ โ€” Cadastro Nacional da Pessoa Jurรญdica

The Brazilian company taxpayer registry number โ€” 14 digits formatted as 00.000.000/0000-00. The first 8 digits identify the company, the next 4 identify the establishment (0001 = headquarters), and the last 2 are check digits.

CPF & CNPJ, Done Right

A complete toolkit for working with Brazilian tax IDs โ€” validation, formatting, and test data generation.

โœ…

Official Algorithm

Uses the exact check-digit algorithm published by Receita Federal โ€” the same one banks, government systems, and tax software use. Catches typos, transposed digits, and made-up numbers.

๐Ÿ”ค

Auto-formatting

Paste a raw 11- or 14-digit number, or one with mixed punctuation โ€” we strip it, validate it, and show the canonical formatted version. Copy the cleaned version with one click.

๐ŸŽฒ

Test Data Generation

Building or testing software that accepts CPF or CNPJ? Generate values with mathematically valid check digits in a single click. Great for unit tests and form validation.

๐Ÿ“‹

One-Click Copy

Validated CPF, validated CNPJ, generated values โ€” all copy to your clipboard with a single tap. Drop straight into forms, spreadsheets, or your codebase.

๐Ÿ”’

100% Private

Everything runs in your browser. The CPF and CNPJ numbers you enter never leave your device, and we don't log them. Safe for use with real customer data.

โšก

Instant Validation

Validation happens as you type โ€” no submit button. Paste a CPF and immediately see whether it's structurally valid or has a check-digit error.

Who Uses This Tool?

Anyone doing business with Brazilian customers, employees, or partners.

๐Ÿ’ป

Developers

Generate test CPF and CNPJ values for unit tests, staging environments, and form validation without leaking real data.

๐Ÿงพ

Accountants

Verify CPFs and CNPJs on supplier or client documents before processing โ€” catch typos before they become tax filing problems.

๐ŸŒ

Cross-border Sellers

Sell to Brazilian customers? Validate buyer CPFs at checkout to reduce payment failures and chargebacks.

๐Ÿ“‹

QA Testers

Quickly produce dozens of valid CPFs and CNPJs to stress-test forms, batch imports, and KYC flows.

Frequently Asked Questions

What is a CPF?

CPF (Cadastro de Pessoas Fรญsicas) is the Brazilian individual taxpayer registry number โ€” Brazil's equivalent of a US Social Security Number or UK National Insurance number. It's an 11-digit identifier issued by Receita Federal, required for nearly any adult activity in Brazil: opening a bank account, signing a contract, buying property, paying taxes, even getting a phone line.

What is a CNPJ?

CNPJ (Cadastro Nacional da Pessoa Jurรญdica) is the Brazilian company taxpayer registry number โ€” 14 digits, the company equivalent of a CPF. It identifies a legal entity (company, NGO, foundation, partnership) for tax purposes. The format is 00.000.000/0000-00: 8 digits for the company, 4 for the establishment (0001 is the headquarters, 0002 the first branch, etc.), and 2 check digits at the end.

How does this validator work?

Both CPF and CNPJ have check digits at the end calculated from the preceding digits using a modulus-11 weighted-sum algorithm published by Receita Federal. The validator runs that exact algorithm on whatever you enter and verifies the check digits match. It catches typos, missing digits, transposed digits, and made-up numbers โ€” but cannot tell you whether the CPF actually belongs to a real person (only Receita Federal's system can do that).

Is a structurally valid CPF guaranteed to belong to someone?

No. The validator checks structural validity โ€” that the check digits are mathematically correct. It does not check whether the number is registered to a real person with Receita Federal. To do that, you need an integration with the official Receita Federal CPF lookup service (paid, requires registration). For most form-validation use cases, the structural check is what you want โ€” it catches the 99%+ of typos and made-up entries.

Are the generated CPFs and CNPJs real?

No. The generator produces random sequences of digits with mathematically valid check digits โ€” but with no relationship to anyone real. They're intended only for software testing and QA. Using a generated CPF to identify yourself or a fictitious person on a real document is fraud and a criminal offence in Brazil. Never use these values on real forms, contracts, or filings.

Why does the CNPJ generator end in /0001?

In a real CNPJ, the four digits before the check digits identify the establishment (filial) โ€” 0001 is the headquarters (matriz). Most companies only have a headquarters, so most real CNPJs end in /0001-XX. The generator uses /0001 by convention because it produces the most realistic-looking test values; the underlying validation is identical regardless.

How are check digits calculated?

For CPF, the first check digit is calculated by multiplying each of the first 9 digits by weights 10, 9, 8, 7, 6, 5, 4, 3, 2; summing the results; taking the remainder modulo 11; and setting the check digit to 0 if the remainder is < 2, otherwise to 11 minus the remainder. The second check digit uses the same algorithm but with the first 10 digits and weights 11 through 2. CNPJ uses a similar weighted-sum approach with different weights (5,4,3,2,9,8,7,6,5,4,3,2 for the first digit). This validator implements both algorithms exactly.

Can I copy the validation logic into my own code?

Yes โ€” the algorithms are public and unpatented. Many JavaScript, Python, and Java libraries already implement them. Search for โ€œcpf cnpj validator [language]โ€ on npm/pip/Maven for ready-made packages, or use the algorithm description above to roll your own โ€” it's about 20 lines of code per type.

A Practical Guide to CPF & CNPJ

Anyone doing business with Brazil quickly runs into CPF and CNPJ. They appear on invoices, contracts, tax filings, shipping labels, KYC forms, and almost any document that names a person or company. Understanding their structure โ€” and being able to validate them โ€” is the difference between a smooth Brazilian operation and one constantly bottlenecked by typos and rejected forms.

CPF โ€” How It's Structured

A CPF has 11 digits, conventionally written with two dots and a hyphen: 123.456.789-09. The first 9 digits are the personal identifier โ€” assigned sequentially by Receita Federal's regional offices. The last 2 are check digits computed from the first 9. The 9th digit (the last of the personal identifier) actually encodes the regional office that issued the CPF: 1 for Sรฃo Paulo, 5 for Bahia/Sergipe, 7 for Rio de Janeiro/Espรญrito Santo, and so on. So if you ever see two friends with the same digit in that position, they likely got their CPFs in the same region.

CNPJ โ€” How It's Structured

A CNPJ has 14 digits: 12.345.678/0001-90. The first 8 digits identify the legal entity. The 4 digits after the slash identify the specific establishment โ€” 0001 is the headquarters (matriz), 0002 is the first branch (filial), and so on. The last 2 digits are check digits. This structure means a single company can have many CNPJs โ€” all sharing the same first 8 digits โ€” one per physical location. Each establishment is independently registered for state-level ICMS but rolls up to the same federal entity.

When to Validate

At form input. The single highest-leverage place to validate is the moment the user types or pastes the value. Inline validation prevents bad data from ever entering your system โ€” and the user fixes it while they still have the right answer in mind.

At batch import. When ingesting CSVs from suppliers, customers, or other systems, validate every CPF and CNPJ on import. Quarantine the invalid ones and ask for corrections rather than silently accepting bad data.

Before generating tax documents. Brazilian tax filings (NF-e, NFC-e, NFS-e, SPED) all require valid CPF or CNPJ on both buyer and seller sides. An invalid one will be rejected by the SEFAZ, and a rejected filing is much more expensive to fix than a check at issuance.

Common Pitfalls

Treating CPF/CNPJ as plain strings. Storing them with mixed formatting (some with punctuation, some without) makes comparison brittle. Always store the 11- or 14-digit raw form in your database and format for display only. Use the formatter in this tool as a reference for the canonical display format.

Using only structural validation for high-risk flows. A structural check stops 99% of typos but won't catch someone who deliberately fabricates a valid-looking CPF. For high-value or fraud-prone flows (banking, lending, payments), integrate with Receita Federal's official lookup or use a commercial KYC provider that does it for you.

All-identical digits passing naive validators. A common bug is implementing the check-digit math without rejecting all-same sequences. Numbers like 111.111.111-11 and 222.222.222-22 actually pass the math check โ€” but Receita Federal never issues them. This validator explicitly rejects them.

Confusing CPF and CNPJ. Customer-facing forms should label the input clearly (โ€œCPF (11 digits)โ€ vs โ€œCNPJ (14 digits)โ€) and validate against the right algorithm. A common usability fix is letting the user type either, and detecting type from length (11 โ†’ CPF, 14 โ†’ CNPJ).

Legal Note on Generated Values

The generator on this page produces CPF and CNPJ values whose check digits are mathematically valid but whose underlying numbers are random and not assigned to any real person or company. They are intended only for software testing โ€” populating test databases, generating placeholder values in QA, stress-testing forms.

Using a generated CPF to identify yourself, sign a contract, register a business, or otherwise represent it as belonging to a real person is fraud under Brazilian law (Cรณdigo Penal Art. 299) and can result in criminal prosecution. If you ever need a real CPF or CNPJ for an actual filing, obtain it through Receita Federal's official channels.

โ˜•