Skip to content

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.

9 min read Updated on July 2026

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.

Example: CPF 123.456.789-09
1 2 3 . 4 5 6 . 7 8 9 - 0 9

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.

Example: CNPJ 11.222.333/0001-81
1 1 . 2 2 2 . 3 3 3 / 0 0 0 1 - 8 1

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.

Frequently Asked Questions

What is a check digit?
A check digit is an extra number added to identification codes (CPF, CNPJ, barcodes) that is mathematically derived from the other digits. It detects typing errors: if any digit is wrong, the check digit calculation will fail, revealing the error.
What is the Modulo 11 algorithm?
Modulo 11 (Mod 11) is a check digit algorithm that multiplies each digit by ascending weights, sums the products, divides by 11, and uses the remainder. It is the most common algorithm in Brazilian document validation (CPF, CNPJ, PIS, bank slips).
Why do CPF and CNPJ have 2 check digits?
Two check digits provide stronger error detection than one. A single check digit can detect any single-digit error, but two check digits can also detect most transposition errors (swapping two adjacent digits) and other multi-digit errors.