What Are CPF and CNPJ?
The CPF & CNPJ Validator instantly checks whether a Brazilian CPF (individual taxpayer) or CNPJ (company) number is mathematically valid. Both documents end in verification digits calculated from the preceding digits with a modulo-11 algorithm. This tool detects automatically whether you typed a CPF (11 digits) or a CNPJ (14 digits), recomputes the check digits, rejects well-known invalid sequences such as repeated digits, and tells you immediately whether the number is valid — formatting it for you. It is ideal for developers validating form input and for anyone double-checking a document, and it runs entirely in your browser so your data stays private.
CPF (Cadastro de Pessoas Físicas) is the Brazilian individual taxpayer registry number — an 11-digit code issued to every Brazilian citizen and resident by the Receita Federal. CNPJ (Cadastro Nacional da Pessoa Jurídica) is the equivalent for legal entities — a 14-digit code assigned to every company, non-profit and government body. Both numbers include check digits that can be mathematically verified, making it possible to detect typos or fabricated numbers instantly without querying any database.
How the Check-Digit Validation Works
CPF validation multiplies each of the first 9 digits by a descending weight (10 down to 2), sums the products, computes remainder mod 11, and derives the first check digit. The process repeats with weights 11 to 2 for the second check digit. CNPJ uses weights 5,4,3,2,9,8,7,6,5,4,3,2 for the first check digit and 6,5,4,3,2,9,8,7,6,5,4,3,2 for the second.
Since 2026, CNPJ numbers can also contain letters in the first eight positions (alphanumeric CNPJ). This tool supports the new format: each character's value is computed as charCode − 48, then the same modular arithmetic applies.
What a valid check digit does and does not prove
Check-digit validation is arithmetic, not identity verification. Understanding the boundary keeps it from being trusted for more than it can carry.
A valid number is not a real person or company
The check digit only proves the number is internally consistent — that its last two digits match what the mod-11 calculation produces from the preceding ones. Millions of consistent numbers were never issued to anybody. Confirming that a document actually exists and belongs to someone requires an official Receita Federal query, not a formula.
Repeated-digit numbers passing a naive check
111.111.111-11 and every other all-same-digit sequence satisfies the mod-11 arithmetic perfectly, which is why home-grown validators wave them through. They are explicitly invalid, so a correct implementation rejects them as a special case before doing anything else. This one does.
Assuming a CNPJ is always numeric
From 2026 the CNPJ accepts letters in its first twelve positions. The check-digit routine is unchanged in shape but each character now contributes its ASCII value minus 48, so digits keep their old weight and letters extend the alphabet. Any validator built on a digits-only regex will start rejecting legitimate new registrations.
Validating the mask instead of the number
Punctuation is presentation, not data. A validator should strip dots, slashes and dashes before doing arithmetic, and store the bare digits. Rejecting an unformatted number, or accepting a well-formatted one without checking the digits, are the two halves of the same mistake.
When to Validate
- Validating CPF or CNPJ numbers entered in a form before submitting to a backend or API.
- Checking whether a document number copied from a receipt or contract is correctly formatted.
- Learning how the CPF/CNPJ check-digit algorithm works for development or compliance purposes.
- Quickly identifying whether a number is a CPF or CNPJ based on its length.
Validation Happens Offline
Document number validation (CPF, CNPJ, DNI, etc.) is performed using JavaScript algorithms that run in your browser. The numbers you enter are validated locally on your device — they never reach our servers.