DNI Letter Calculation Algorithm - How is the letter calculated?

The DNI letter calculation algorithm is a mathematical system that allows verifying the validity of a DNI and detecting transcription errors. This system was introduced in 1962 and remains fundamental in the validation of Spanish identity documents.

Related tools:

How is the DNI letter calculated?

  1. Take the DNI number (8 digits)
  2. Divide it by 23
  3. Take the remainder of the division (modulo)
  4. Look up the corresponding letter in the table

Mathematical formula

Letter = TABLE[dni_number MOD 23]

Where MOD is the "modulo" operation (remainder of the division)

Correspondence table

Remainder Letter Remainder Letter Remainder Letter
0T 8P 16Q
1R 9D 17V
2W 10X 18H
3A 11B 19L
4G 12N 20C
5M 13J 21K
6Y 14Z 22E
7F 15S

Practical example

For the DNI number 12345678:

  1. 12345678 ÷ 23 = 536768.608...
  2. 0.608... × 23 = 14 (remainder)
  3. Remainder 14 → Letter 'Z'
  4. Complete DNI: 12345678Z

Why 23?

The number 23 was chosen because:

  • It is a prime number
  • It allows using 23 different letters (excluding I, Ñ, O, U)
  • It minimizes transcription errors

Excluded letters

The following letters are not used in the DNI:

  • I: To avoid confusion with the number 1
  • Ñ: Because it is a special character
  • O: To avoid confusion with the number 0
  • U: To avoid confusion in writing

Frequently asked questions

Can two DNIs have the same letter?

Yes, different numbers can have the same letter if when divided by 23 they give the same remainder.

Can the number be calculated from the letter?

No, since multiple numbers can have the same letter. The letter only serves to verify.

Has the algorithm ever changed?

No, the algorithm has remained the same since its introduction in 1962 to maintain compatibility.