Asistente RD

Spain DNI/NIE letter calculator

Work out the check letter of a Spanish DNI or NIE in seconds with the official mod-23 algorithm, and validate whether a full ID number is typed right.

Free · No sign-up · In your browser

With or without the final letter: 12345678, 12345678Z, X1234567…

Result

12345678Z

Type

DNI

Number used for the calculation

12345678

Remainder mod 23

14

Letter

Z

Everything runs in your browser: the number is never stored or sent to a server. The letter only catches typing mistakes; it does not confirm that the document exists or belongs to a specific person.

Share on WhatsApp Last reviewed: July 9, 2026

What the DNI letter is and why it exists

Every Spanish national ID card (DNI) ends in a letter, and that letter is not random: it is a check character derived mathematically from the ID number itself. Its only job is to catch typing mistakes. If a single digit is copied wrong on a form, the letter no longer matches and the system can flag the error before it causes trouble with a contract, a payroll record or a university enrolment.

The same applies to the NIE, the identity number issued to foreign residents in Spain, which starts with X, Y or Z. Its final letter is produced by the very same algorithm after the leading letter is converted into a digit.

This calculator works both ways. Type just the number and it returns the letter plus the full document ready to copy. Type the complete ID (number + letter) and it validates it, telling you whether the letter is right and, if not, which one it should be. Everything runs in your browser and nothing is sent to any server.

How to use the calculator

  1. Enter a DNI number (1 to 8 digits) or a NIE (X, Y or Z followed by 7 digits). Dots, spaces and dashes are stripped automatically, so you can paste the number as it appears anywhere.
  2. Leave the letter out to calculate it.
  3. Include the final letter to validate the whole document: the tool confirms a match or shows the correct letter.

The method: divide by 23

The algorithm published by Spain’s Interior Ministry is remarkably simple:

  1. Take the ID number without its letter.
  2. Divide it by 23 and keep the remainder (the modulo operation).
  3. The remainder is always between 0 and 22; look up its letter in this table:
RemainderLetterRemainderLetterRemainderLetter
0T8P16Q
1R9D17V
2W10X18H
3A11B19L
4G12N20C
5M13J21K
6Y14Z22E
7F15S

For a NIE, one extra step comes first: the leading letter is replaced by a digit — X becomes 0, Y becomes 1 and Z becomes 2 — and the resulting 8-digit number is divided by 23 in exactly the same way.

Worked example

DNI 12345678. Dividing gives 12345678 ÷ 23 = 536768 with a remainder: since 23 × 536768 = 12345664, the remainder is 12345678 − 12345664 = 14. Remainder 14 maps to the letter Z, so the full document is 12345678Z.

NIE X1234567. The X turns into 0, producing 01234567, which is the number 1234567. Since 23 × 53676 = 1234548, the remainder is 1234567 − 1234548 = 19. Remainder 19 maps to the letter L, so the complete NIE is X1234567L.

You can check both results by typing them into the calculator above.

Frequently asked questions

Why are the letters I, Ñ, O and U missing from the table?

They were deliberately left out to avoid misreadings: I looks like 1, O looks like 0, U can be confused with V, and Ñ may break in systems that do not handle Spanish characters. That leaves exactly 23 letters, one for each possible remainder.

Is the NIE letter calculated the same way as the DNI letter?

Yes, with one preliminary step: the NIE’s leading letter is swapped for a digit (X for 0, Y for 1, Z for 2) and the resulting 8-digit number is divided by 23. The letter table is identical.

Does a correct letter mean the ID actually exists?

No. A matching letter only proves that the number and the letter are consistent with each other — in other words, that there is no typo. Any number from 0 to 99999999 produces a “valid” letter whether or not that DNI has ever been issued. The tool does not query any official registry.

What if a DNI has fewer than 8 digits?

Nothing changes: older DNIs with 7 digits (or fewer) are calculated the same way, because leading zeros do not affect the result of the division. Type the number exactly as it appears on the card.

Can I use this for a Spanish company tax ID (CIF)?

No. The CIF — now the NIF for legal entities — uses a different algorithm based on position-weighted sums. This tool covers the DNI of Spanish citizens and the NIE of foreign residents.

Related tools