Check Digits
CPF uses weights 10–2, CNPJ uses weights 5,4,3,2,9,8,7,6,5,4,3,2. Modulo 11 algorithm explained step-by-step for CPF, CNPJ, PIS and RENAVAM with worked examples.
In this guide, you will:
- Understand what a check digit is and why it exists
- Learn the Modulus 11 algorithm step by step
- See the calculation applied to CPF, CNPJ, PIS and RENAVAM
- Know when Modulus 10 is used instead
Check digits are extra numbers appended to identification codes to detect typing errors and prevent fraud. They are calculated using mathematical algorithms applied to the other digits. Most Brazilian documents use the Modulo 11 algorithm.
Modulus 11 algorithm
The Modulo 11 algorithm works by multiplying each digit by a weight (usually starting from 2 and increasing), summing the results, dividing by 11, and using the remainder to determine the check digit. If the remainder is 0 or 1, the check digit is 0; otherwise, it is 11 minus the remainder.
int CalcularDigito(int[] digitos, int[] pesos)
{
int soma = 0;
for (int i = 0; i < digitos.Length; i++)
soma += digitos[i] * pesos[i];
int resto = soma % 11;
return resto < 2 ? 0 : 11 - resto;
}
Note
Modulus 11 is the most common, but not the only one: bank slips (boletos) and some codes use Modulus 10, with alternating weights of 2 and 1.
CPF — check digits
The CPF has 2 check digits (10th and 11th). The first is calculated from the 9 base digits using weights 10 to 2. The second is calculated from the 10 digits (9 base + 1st check digit) using weights 11 to 2. Both use the Modulo 11 algorithm.
1st digit: weights 10,9,8,7,6,5,4,3,2 → sum 210 → 210 % 11 = 1 → 11 − 1 = 10 → 0
2nd digit: includes the 1st check digit and repeats the process
CNPJ — check digits
The CNPJ also has 2 check digits (13th and 14th). The first is calculated from the 12 base digits using weights 5,4,3,2,9,8,7,6,5,4,3,2. The second uses the 13 digits with weights 6,5,4,3,2,9,8,7,6,5,4,3,2.
1st digit: weights 5,4,3,2,9,8,7,6,5,4,3,2 · 2nd digit: weights 6,5,4,3,2,9,8,7,6,5,4,3,2
Just want to check a number? Use the Validate CPF Online Free — Instant Check or the Validate CNPJ Online Free — Instant Check and watch the digit be verified instantly.
PIS/PASEP
The PIS/PASEP has 1 check digit (11th). It uses the Modulo 11 algorithm with weights 3,2,9,8,7,6,5,4,3,2 applied to the first 10 digits.
RENAVAM
The RENAVAM has 1 check digit (11th). It uses a Modulo 11 variant with weights 3,2,9,8,7,6,5,4,3,2 and the formula (sum * 10) % 11. If the result is 10 or more, the check digit is 0.
Every Brazilian document with a check digit follows the same idea: multiply by weights, sum, and take the remainder of the division. Once you understand Modulus 11, you can validate CPF, CNPJ, PIS and more — or let the tools below do the math.