CPF Validator

Check whether a CPF is valid and see the issuing fiscal region. Learn the check digit calculation (Modulo 11) with a code example.

Validated in your browser to protect your privacy.

Enter the complete CPF to validate

About this tool

The CPF (Cadastro de Pessoas Físicas), Brazil's individual taxpayer registry number, is made up of 11 digits. The first nine form the base number, where the 9th digit indicates the region in which the CPF was originally issued, and the last two are the check digits (Dígitos Verificadores, or DV). These digits are calculated to reduce typing errors and validate the consistency of the number. The calculation is based on the Modulo 11 algorithm, widely used in identification systems. On this page, you can enter a CPF and instantly check whether its check digits are valid according to that algorithm.

Features

CPF validation using the official modulo 11 algorithm
Identification of the issuing fiscal region

Understand how the CPF check digit calculation works

1. Calculating the First Check Digit

The calculation of the first check digit (the 10th digit of the CPF) uses only the first nine digits of the base number.

  • Multiply the first digit by 10, the second by 9, the third by 8, and so on, until the ninth digit is multiplied by 2.
  • Add up all the results of the multiplications.
  • Divide the sum by 11 and take the remainder.
  • If the remainder is less than 2, the first check digit is 0.
  • Otherwise, the first check digit is 11 minus the remainder.

2. Calculating the second check digit

The calculation of the second check digit (the 11th digit of the CPF) follows the same process, but now uses the nine digits of the base number plus the first check digit, totaling 10 digits.

  • Multiply the first digit by 11, the second by 10, the third by 9, and so on, until the first check digit is multiplied by 2.
  • Add up all the results of the multiplications.
  • Divide the sum by 11 and take the remainder.
  • If the remainder is less than 2, the second check digit is 0.
  • Otherwise, the second check digit is 11 minus the remainder.

Practical example in JavaScript

Below is a common, optimized JavaScript function to validate both check digits of a CPF:

One detail before looking at the code: above, the rule was presented as "if the remainder of the division by 11 is less than 2, the digit is 0". In the code, the logic appears differently: first 11 - (sum % 11) is calculated, and then the results 10 and 11 are converted to 0. Although they look like different approaches, both implement exactly the same rule. The second form is simply the most common one in implementations of this algorithm.

JavaScript
function validateCPF(cpf) {
  if (typeof cpf !== 'string') {
    return false;
  }

  cpf = cpf.replace(/\D/g, '');

  if (cpf.length !== 11 || /^(\d)\1{10}$/.test(cpf)) {
    return false;
  }

  let sum = 0;

  // First check digit
  for (let i = 0; i < 9; i++) {
    sum += Number(cpf[i]) * (10 - i);
  }

  let digit = 11 - (sum % 11);
  if (digit > 9) digit = 0;

  if (digit !== Number(cpf[9])) {
    return false;
  }

  // Second check digit
  sum = 0;

  for (let i = 0; i < 10; i++) {
    sum += Number(cpf[i]) * (11 - i);
  }

  digit = 11 - (sum % 11);
  if (digit > 9) digit = 0;

  return digit === Number(cpf[10]);
}

CPF 9th Digit by Fiscal Region

The 9th digit of every CPF corresponds to the fiscal region where the document was issued. Check the table below for the region matching each numeric code:

DigitStates
0Rio Grande do Sul (RS)
1Distrito Federal (DF), Goiás (GO), Mato Grosso (MT), Mato Grosso do Sul (MS), Tocantins (TO)
2Acre (AC), Amapá (AP), Amazonas (AM), Pará (PA), Rondônia (RO), Roraima (RR)
3Ceará (CE), Maranhão (MA), Piauí (PI)
4Alagoas (AL), Paraíba (PB), Pernambuco (PE), Rio Grande do Norte (RN)
5Bahia (BA), Sergipe (SE)
6Minas Gerais (MG)
7Espírito Santo (ES), Rio de Janeiro (RJ)
8São Paulo (SP)
9Paraná (PR), Santa Catarina (SC)

How to Use

1

Enter the CPF

Type or paste the CPF. Dots and the dash are optional. Validation happens automatically as soon as the 11th digit is entered.

2

Check the result

The tool tells you whether the CPF is valid or invalid, and if valid, it also shows the issuing fiscal region.

Use Cases

  • Catch typing errorsValidating a CPF before using it in registrations or forms helps you quickly spot typing errors.
  • Debug your own validationCompare your code's behavior against a reliable result if your implementation rejects numbers that should pass.

Questions and Answers

How do I know if a CPF is valid?

A CPF is mathematically valid when the last two digits, known as the check digits (Dígitos Verificadores, or DV), match the result of the Modulo 11 algorithm applied to the first nine digits. Enter the number in the field above and the page runs this validation automatically. This check confirms only the mathematical consistency of the CPF. To find out whether a CPF is real, has been issued, and is in good standing, you need to consult the Receita Federal, Brazil's federal tax authority.

Does a valid result mean the CPF exists at the Receita Federal?

No. The validation performed here is purely mathematical: it only confirms that the check digits are consistent with the number entered. A CPF can pass this check and never have been issued to a person, as happens with numbers generated for testing. It may also correspond to a real CPF whose registration status is irregular, suspended, or cancelled. Only the Receita Federal has access to the official registration status of a CPF.

See also