CNPJ Validator

Check if a CNPJ is mathematically valid. Supports both the traditional format and the new alphanumeric format.

How to validate a CNPJ?

CNPJ validation consists of checking whether the last two digits (check digits) are correct according to the modulo 11 algorithm. This algorithm applies a series of multiplications and mathematical operations on the first 12 characters of the CNPJ to calculate what the check digits should be.

The validation process follows these steps: first, formatting is removed (dots, slash and hyphen); then, the CNPJ is checked for exactly 14 characters; next, the first check digit is calculated and compared with the 13th character; finally, the second check digit is calculated including the first, and compared with the 14th character.

If both calculated check digits match those present in the CNPJ, the number is considered mathematically valid. Otherwise, there is an error in the number provided.

Common invalid CNPJs

Some CNPJ patterns are known to be invalid, even if they technically pass the digit check. CNPJs with all identical digits (such as 11.111.111/1111-11 or 00.000.000/0000-00) are considered invalid, as the modulo 11 algorithm may return "correct" check digits for these patterns.

Common errors include swapping digit order, omitting the branch digit, or confusing the CNPJ with CPF (which has 11 digits). Our validator detects all these cases and reports exactly which step the validation failed at.

Another frequent error is typing CNPJs with invalid special characters or with more/less than 14 characters. The validator accepts input with or without formatting and automatically normalizes before validating.

Difference between valid CNPJ and active CNPJ

It is essential to understand the difference between a mathematically valid CNPJ and a CNPJ that is active with the Federal Revenue. Mathematical validation only confirms that the check digits are correct β€” meaning the number does not contain typing errors.

A CNPJ can be mathematically valid but not exist as a registration with the Federal Revenue (like those created by our CNPJ Generator). Similarly, a registered CNPJ may have a registration status of "Closed", "Suspended" or "Unfit".

To verify if a CNPJ is truly active and in regular standing with the Federal Revenue, use our CNPJ Search tool, which queries official registration data directly.

How to validate the new Alphanumeric CNPJ?

Our validator already supports the new alphanumeric CNPJ format, which takes effect in July 2026. Validation automatically detects whether the provided CNPJ is traditional (numbers only) or alphanumeric (with letters and numbers).

For alphanumeric CNPJs, the validation algorithm is the same modulo 11, but with the conversion of letters to numeric values: A=17, B=18, C=19, up to Z=42. Digits keep their normal value (0 to 9). The last two characters (check digits) are always numeric in both formats.

Systems and developers that need to validate CNPJs should update their implementations to accept the new format. Our CNPJ query API will also be updated to support queries with the alphanumeric format.

CNPJ validation in code

To implement CNPJ validation in your system, the algorithm involves three main steps: input normalization (remove formatting and convert to uppercase), calculation of the first check digit with weights [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], and calculation of the second digit with weights [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2].

To support the alphanumeric format, simply map each character to its numeric value before multiplication: digits keep their face value, letters use the mapping A=17 through Z=42. The rest of the algorithm remains identical.

If you need production-ready CNPJ validation with real-time data, consider using the cnpj-api.com API, which validates the format and also checks registration status with the Federal Revenue.

Frequently Asked Questions

Does valid CNPJ mean the company exists?+
Not necessarily. Validation only checks whether the check digits are mathematically correct. To confirm if the company exists and is active, query the Federal Revenue using our CNPJ Search tool.
How to check the registration status of a CNPJ?+
Use our CNPJ Search tool to query registration data, registration status, economic activities and partners of any CNPJ registered with the Federal Revenue.
Does the validator work with the new alphanumeric CNPJ?+
Yes. Our validator automatically detects the format (traditional or alphanumeric) and applies the correct validation algorithm, including the letter-to-numeric-value mapping.
Why does my CNPJ appear as invalid?+
Check that all 14 digits were entered correctly, including the branch digits. Typing errors in the check digits are the most common cause. If the CNPJ was randomly generated, the check digits are likely incorrect.
What is the difference between this validator and querying the Federal Revenue?+
This validator checks the mathematical validity of the number (check digits). Querying the Federal Revenue checks whether the CNPJ is actually registered and what its registration status is (active, closed, suspended, etc.).