Calculating the NIF/NIE check digit

DNI issuing is regulated under Royal Decree 1553/2005 of 23 ?December; article 11 therein states that said document includes the personal national identification number and a checksum letter corresponding to the tax identification number.

Tax identification numbers of adult Spanish residents can be verified by calculating their checksum letter using the following algorithm:

  • The number is divided by 23 and the remainder is replaced by a letter determined by the following table:

?

REMAINDER 0 1 2 3 4 5 6 7 8 9 10 11
LETTER T R W A G M Y F P D X B

?

REMAINDER 12 13 14 15 16 17 18 19 20 21 22
LETTER N J Z S Q V H L C K E

?

For example, if the DNI number is 12345678, this, divided by 23 leaves a remainder of 14, therefore the letter is Z: 12345678Z.

Non-nationals residing in Spain have a NIE (Número de Identidad de Extranjero) which is made up of a letter (X, Y, Z), 7 numbers and a?check digit.

To calculate the check digit, each letter is replaced by a number:

  • X → 0
  • Y → 1
  • Z → 2

and the same algorithm is used.