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:
- DNI Letter Calculator - Calculate the letter automatically
- DNI Validator - Check if a DNI is valid
How is the DNI letter calculated?
- Take the DNI number (8 digits)
- Divide it by 23
- Take the remainder of the division (modulo)
- 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 |
---|---|---|---|---|---|
0 | T | 8 | P | 16 | Q |
1 | R | 9 | D | 17 | V |
2 | W | 10 | X | 18 | H |
3 | A | 11 | B | 19 | L |
4 | G | 12 | N | 20 | C |
5 | M | 13 | J | 21 | K |
6 | Y | 14 | Z | 22 | E |
7 | F | 15 | S |
Practical example
For the DNI number 12345678:
- 12345678 ÷ 23 = 536768.608...
- 0.608... × 23 = 14 (remainder)
- Remainder 14 → Letter 'Z'
- 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.