utilduck
Home · Office · Spanish DNI/NIE Letter Calculator

Spanish DNI/NIE Letter Calculator

Enter a DNI (8 digits) or NIE (X/Y/Z + 7 digits), with or without the letter, to calculate or validate it.

Result
-

How the DNI/NIE check letter is calculated

The check letter validates a Spanish DNI or NIE number using a fixed algorithm: divide the 8-digit number by 23, and use the remainder to pick a letter from the string 'TRWAGMYFPDXBNJZSQVHLCKE' (0-indexed). For a NIE, the leading letter is first replaced with a digit — X becomes 0, Y becomes 1, Z becomes 2 — before applying the same calculation. This lets you both generate the correct letter for a new number and confirm that an existing DNI/NIE is not mistyped.

How do I calculate the DNI/NIE check letter?

To calculate the check letter, take the 8-digit number (for a NIE, first replace the leading letter with a digit: X=0, Y=1, Z=2), divide it by 23, and use the remainder as an index into the fixed string 'TRWAGMYFPDXBNJZSQVHLCKE'. Example: 12345678 mod 23 = 15, and the letter at index 15 is 'Z'.

Steps to calculate or validate

  1. If the input starts with X, Y or Z (a NIE), replace that letter with 0, 1 or 2 respectively to form an 8-digit number.
  2. Take the resulting 8-digit number as-is for a DNI.
  3. Divide the 8-digit number by 23 and keep the remainder (0-22).
  4. Look up that remainder as a position in the string 'TRWAGMYFPDXBNJZSQVHLCKE' (position 0 = T) to get the check letter.
  5. If a letter was already provided, compare it to the calculated one to determine validity.

Formula

Letter = "TRWAGMYFPDXBNJZSQVHLCKE"[number mod 23]
  • number = the 8-digit DNI number, or the NIE number with X/Y/Z replaced by 0/1/2
  • mod 23 = the remainder after dividing by 23, always between 0 and 22
  • the 23-letter reference string skips vowels and letters easily confused with digits, by official design

Quick DNI/NIE answers

What letter goes with DNI 12345678?

Z. 12345678 mod 23 is 14, and the character at position 14 (counting from 0) in the fixed 23-letter table 'TRWAGMYFPDXBNJZSQVHLCKE' is Z.

How is the DNI letter table built -- is it alphabetical?

No, it's a fixed non-alphabetical sequence, 'TRWAGMYFPDXBNJZSQVHLCKE' -- the position (DNI number mod 23) picks the letter; it isn't computed directly from the alphabet.

What letter goes with NIE X1234567?

L. The X prefix is replaced with 0, giving the number 1234567; 1234567 mod 23 is 19, which is L.

What letter goes with NIE Y1234567?

X. The Y prefix is replaced with 1, giving 11234567; 11234567 mod 23 is 10, which is X.

What letter goes with NIE Z1234567?

R. The Z prefix is replaced with 2, giving 21234567; 21234567 mod 23 is 1, which is R.

What letter corresponds to DNI 00000000?

T -- 0 mod 23 is 0, and the first letter (position 0) in the table is T.

Does the DNI letter change if the number is written with leading zeros?

No -- the calculation always uses the full 8-digit number as-is; leading zeros are part of the number, not stripped before the mod-23 calculation.

Can two different DNI numbers share the same letter?

Yes -- since there are only 23 possible letters but far more possible 8-digit numbers, each letter is shared by roughly 1 in 23 numbers; the letter alone can't identify a specific DNI.

Example DNI numbers and their letters

Numbermod 23Letter
1234567815Z
000000000T
8765432121X
2500000013N
999999991R

Frequently asked questions

What is the difference between DNI and NIE?

DNI (Documento Nacional de Identidad) is issued to Spanish citizens and is always 8 digits plus a letter. NIE (Número de Identidad de Extranjero) is issued to foreign residents and starts with X, Y or Z followed by 7 digits and a letter.

Why does a NIE replace its letter with a digit before calculating?

The check-letter algorithm was designed for an 8-digit number. Since a NIE only has 7 digits after its leading letter, that letter is mapped to a digit (X=0, Y=1, Z=2) to complete the 8-digit number before applying the same modulo-23 formula as a DNI.

Can this tool detect a fake or made-up DNI number?

It can confirm the check letter is mathematically consistent with the 8 digits, which catches typos and randomly invented numbers. It cannot confirm the number was actually issued by the Spanish authorities — that requires an official registry lookup.

Why do letters like I, O and U never appear?

The reference string 'TRWAGMYFPDXBNJZSQVHLCKE' intentionally excludes vowels and visually similar letters/digits to reduce transcription errors when the ID is read aloud or copied by hand.

This tool implements the public check-letter algorithm only; it does not verify that a DNI/NIE was actually issued, is currently valid, or belongs to a real person. Use an official government service for identity verification.

Privacy and safety

  • Runs in your browser — Everything you type is calculated on your own device. Your inputs are never sent to a utilduck server.
  • Encrypted connection — Pages are served over HTTPS, so nobody on the network can read what you load.
  • Not shared with third parties — Your inputs are not passed to analytics or advertising services.
  • Nothing is stored — Results are not saved to any server, and there is no account to create.

Last updated: 2026-08-17