Valid CPF (synthetic)
- Input
- 111.444.777-35
- Expected output
- válido: dígito esperado 35, dígito recebido 35
Recalculating over base 111444777 returns exactly the two digits provided, so the validator approves without needing anything else.
check digit validation algorithm
Validating a CPF or CNPJ is not about checking a string length: it means redoing the same weighted sum that generated the document and comparing the result against its last two digits. This page walks through that algorithm working, and failing, with concrete numbers.
Recalculating over base 111444777 returns exactly the two digits provided, so the validator approves without needing anything else.
Same base, same calculation, same expected result as the previous example; only the provided digit changed, and that alone is enough for the algorithm to reject it.
The recalculation confirms 11 is the mathematically correct digit for this base; the rejection comes from a separate filter for repeated sequences, not from the arithmetic.
Yes. Local validation checks the length (11 digits for CPF, 14 for CNPJ), rejects common invalid patterns like all-equal digits, and recomputes the check digits with modulo 11, comparing them against the ones entered. If the math matches, the number is considered well-formed. That applies to both numeric CNPJ and the new alphanumeric CNPJ with letters, which the tool detects automatically.
The idea is the same, modulo 11 twice over a weighted sum, but the weights differ because a CNPJ base has 12 characters against a CPF 9; CNPJ weights reset at the fifth position, CPF weights just descend to the end.
It can, and that is exactly what happens with 111.111.111-11: modulo 11 closes the calculation. The Receita Federal never issues a number like that, so validators treat repeated sequences as a test separate from the arithmetic.
Yes, because it recalculates both check digits from the leading digits and compares them against what was typed; any error in the check digits or in the base changes the weighted sum and breaks the comparison.
Because the algorithm only redoes a math calculation over the digits provided, without querying any official registry; a number can close modulo 11 perfectly and still have never been issued to anyone.
The number passed the mathematical check digit rule. This does not confirm registry existence.
CPF/CNPJ can be personal data. Validation is local and does not query government systems or save the number.