PatternFly logo

ℂℕℙ𝕁 β„‚π•™π•–π•”π•œ π”»π•šπ•˜π•šπ•₯

How to Calculate CNPJ Check Digit ?

A CNPJ is only valid if it is registered with the Federal Revenue Service .
The CNPJ is composed of 14 digits, the last two verification digits.

It is divided into three blocks:

- the first represents the registration number of the legal entity;
- the second represents a unique code for the head office or branch (after the slash);
- the third is the check digits (DV).

Through the check digits we can know if it has the correct format without having to consult the IRS.

 

See here how the generation of CNPJ check digits is done.

Calculation of the first check digit

With the 12 digits of the CNPJ, do the following operations:

multiply the first digit by 5
multiply the second digit by 4
multiply the third digit by 3
multiply the fourth digit by 2
multiply the fifth digit by 9
multiply the sixth digit by 8
multiply the seventh digit by 7
multiply the eighth digit by 6
multiply the ninth digit by 5
multiply the tenth digit by 4
multiply the eleventh digit by 3
multiply the twelfth digit by 2

Add up all the results and divide the total by 11.
Subtract the remainder found of 11, ie 11 - REST.
If the result is less than 2, the first check digit is 0 (zero).
Otherwise, the first check digit is the result of the subtraction.

Calculation of the second check digit

To get the second check digit, do the same procedure as the first check digit. This time considering the first check digit already calculated.
With the 13 digits of the CNPJ (the 12 plus the first check digit) in hand, do the following operations:

multiply the first digit by 6
multiply the second digit by 5
multiply the third digit by 4
multiply the fourth digit by 3
multiply the fifth digit by 2
multiply the sixth digit by 9
multiply the seventh digit by 8
multiply the eighth digit by 7
multiply the ninth digit by 6
multiply the tenth digit by 5
multiply the eleventh digit by 4
multiply the twelfth digit by 3
multiply the thirteenth digit by 2

Add up all the results and divide the total by 11.
Subtract the remainder found from 11, ie 11 - REST.
If the result is less than 2, the second check digit is 0 (zero).
Otherwise, the second check digit is the result of the subtraction.

Practical example

Considering CNPJ 12.345.678/0001

Calculating the first check digit

multiplying the first digit by 5 (1 x 5 = 8)
multiplying the second digit by 4 (2 x 4 = 8)
multiplying the third digit by 3 (3 x 3 = 9)
multiplying the fourth digit by 2 (4 x 2 = 8)
multiplying the fifth digit by 9 (5 x 9 = 45)
multiplying the sixth digit by 8 (6 x 8 = 48)
multiplying the seventh digit by 7 (7 x 7 = 49)
multiplying the eighth digit by 6 (8 x 6 = 48)
multiplying the ninth digit by 5 (0 x 5 = 0)
multiplying the twelfth digit by 4 (0 x 4 = 0)
multiplying the eleventh digit by 3 (0 x 3 = 0)
multiplying the twelfth digit by 2 (1 x 2 = 2)

Adding up all the results (5 + 8 + 9 + 8 + 45 + 48 + 49 + 48 + 0 + 0 + 0 + 2 = 222)
Dividing the total by 11 (222 / 11)
The remainder of this division is 2
Subtracting the remainder found out of 11 (11 - 2 = 9).
The result is greater than 2, so the first check digit is 9 (nine).

Calculating the second check digit

multiplying the first digit by 6 (1 x 6 = 6)
multiplying the second digit by 5 (2 x 5 = 10)
multiplying the third digit by 4 (3 x 4 = 12)
multiplying the fourth digit by 3 (4 x 3 = 12)
multiplying the fifth digit by 2 (5 x 2 = 10)
multiplying the sixth digit by 9 (6 x 9 = 54)
multiplying the seventh digit by 8 (7 x 8 = 56)
multiplying the eighth digit by 7 (8 x 7 = 56)
multiplying the ninth digit by 6 (0 x 6 = 0)
multiplying the twelfth digit by 5 (0 x 5 = 0)
multiplying the eleventh digit by 4 (0 x 4 = 0)
multiplying the twelfth digit by 3 (1 x 3 = 3)
multiplying the thirteenth digit by 2 (9 x 2 = 18)

Adding up all the results (6 + 10 + 12 + 12 + 10 + 54 + 56 + 56 + 0 + 0 + 0 + 3 + 18 = 237)
Dividing the total by 11 (237 / 11)
The remainder of this division is 6
Subtracting the remainder found from 11 (11 - 6 = 5).
The result is equal to 5 (which is greater than 2), so the second check digit is 5.

Final result: 12,345,678/0001-95

CPF Generator
CPF Validator
π”Ήπ•£π•’π•«π•šπ• ℂℕℙ𝕁
CNPJ Validator
How it Works
CNPJ Generator