Spanish DNI Letter Calculator
Enter the numbers of your Spanish DNI or NIE and get the correct check letter instantly. Calculation is done in your browser.
The letter on a Spanish DNI is not random: it is a check digit calculated mathematically from the number. Its purpose is to detect errors in number entry (as with bank IBANs or book ISBNs). The algorithm applies modulo 23 to the number and the result is converted to a letter using the official table TRWAGMYFPDXBNJZSQVHLCKE.
This calculator also works for the NIE (Número de Identidad de Extranjero), which begins with X, Y or Z. Before applying the modulo, those letters are replaced by 0, 1 and 2 respectively. The result is instant and the calculation is done in your own browser, without sending any data to any server.
This tool is only for verifying the letter. For any official matters related to the DNI, contact the relevant authorities.
How is the letter calculated?
The DNI number is divided by 23 and the remainder is taken. That remainder (0 to 22) corresponds to a letter according to the official table TRWAGMYFPDXBNJZSQVHLCKE. For the NIE, the initial letter X, Y or Z is replaced by 0, 1 or 2 before calculating.
The DNI letter algorithm step by step
The calculation is based on a modulo operation, very common in check-digit systems. The procedure has three steps. First, take the full DNI number, without the letter, as an integer of up to eight digits. Second, divide that number by 23 and keep only the remainder, which will necessarily be a value between 0 and 22. Third, use that remainder as an index into the control string TRWAGMYFPDXBNJZSQVHLCKE, counting from position 0. The letter at that position is the DNI letter. In the case of the NIE, the leading letter X, Y or Z is first replaced by 0, 1 or 2 and then the same procedure is applied.
Worked example
Take the number 12345678. We divide it by 23: 12345678 / 23 = 536768 with a remainder of 14, since 536768 × 23 = 12345664 and 12345678 − 12345664 = 14. Now we look up position 14 in the string TRWAGMYFPDXBNJZSQVHLCKE, counting from zero: T(0), R(1), W(2), A(3), G(4), M(5), Y(6), F(7), P(8), D(9), X(10), B(11), N(12), J(13), Z(14). The letter is Z, so the complete DNI would be 12345678-Z.
Control table: remainder and matching letter
Remainder 0
T
Remainder 1
R
Remainder 2
W
Remainder 3
A
Remainder 4
G
Remainder 5
M
Remainder 6
Y
Remainder 7
F
Remainder 8
P
Remainder 9
D
Remainder 10
X
Remainder 11
B
Remainder 12
N
Remainder 13
J
Remainder 14
Z
Remainder 15
S
Remainder 16
Q
Remainder 17
V
Remainder 18
H
Remainder 19
L
Remainder 20
C
Remainder 21
K
Remainder 22
E
What the letter is actually for
The DNI letter is a check digit, not identifying data. Its only function is to detect errors when typing or transcribing the number, and it does so remarkably well: if you get a single digit wrong, the probability that the letter still matches is roughly 1 in 23, around 4%. That means the system catches about 96% of single-digit errors before they reach a database. This is why forms at banks, public administrations and online shops validate the letter as soon as you enter the number. Bear in mind, however, that validating the letter only confirms the number is internally consistent, not that it belongs to a real person.