Spain DNI / NIE Validator

Check the control letter of a Spanish DNI (national ID) or NIE (foreigner ID) using the official modulo-23 algorithm. 100% local. Built for Spain.

Result

Batch check — paste many, one per line

Validate a Spanish DNI or NIE

Enter a DNI (8 digits + letter) or NIE (X/Y/Z + 7 digits + letter) to verify its control letter. Everything runs locally in your browser.

How the DNI and NIE control letter works

Spain's identity numbers end in a letter that is not chosen at random: it is computed from the digits with a modulo 23 rule published by the Ministry of the Interior. Because of it, a single mistyped or swapped digit almost always produces a different letter, which is why banks, tax forms and online services can reject a typo instantly.

Structure

DocumentFormatWho gets it
DNI8 digits + control letterSpanish citizens. Numbers below 10 000 000 are written with a leading zero. The same number followed by the letter is the person's tax number (NIF).
NIEX, Y or Z + 7 digits + control letterForeign nationals living, working or investing in Spain. X was used for the first series, Y for numbers from 10 000 000 onwards, and Z is reserved for the series after that.

Company tax numbers (the former CIF, starting with a letter such as A or B) follow a different rule and are outside the scope of this tool.

Worked example: DNI 12345678

Divide the number by 23 and keep only the remainder. Then read the letter at that position in the official table, where position 0 is T.

Number12345678
Divided by 23536768 remainder 14
Letter at position 14Z
Result12345678Z

For a NIE the prefix letter is first turned into a digit: X becomes 0, Y becomes 1 and Z becomes 2. So Y1234567 is checked as 11234567, whose remainder modulo 23 is 10, giving the letter X: Y1234567X. This prefix rule exists so that X1234567 and Y1234567 do not end up with the same letter.

The 23-letter table

Remainder012345678910111213141516171819202122
LetterTRWAGMYFPDXBNJZSQVHLCKE

The letters I and O are skipped because they look like 1 and 0 on printed documents, Ñ is skipped because it is missing from most foreign keyboards, and U was dropped so that exactly 23 letters remain. 23 is a prime number, which makes the check stronger than a table based on the full alphabet would be.

Official sources

Common mistakes and what the letter cannot tell you

  • Leaving out a leading zero: a DNI such as 01234567X has 8 digits including the zero. Typed as 7 digits, it is reported as a format error.
  • Confusing the two letters of a NIE: the first letter (X, Y or Z) is part of the number, the last letter is the check.
  • Reading O as 0 or I as 1 on a scan or photocopy. The control table never uses I, O or U, so a control letter that reads as one of those was transcribed wrongly.
  • A correct letter proves only that the digits were copied correctly. It does not prove the document exists, is still valid or belongs to the person presenting it; identity must be verified against the document itself or an official service.
  • Lowercase letters and spaces are accepted by the tool and normalised before checking.

Spain's DNI is 8 digits plus a control letter; the NIE (for foreign residents) swaps the first character for X, Y or Z. The control letter is pure math, defined in official regulations: the number modulo 23 indexes the sequence TRWAGMYFPDXBNJZSQVHLCKE. For NIE, replace X/Y/Z with 0/1/2 before computing. This tool recomputes the letter locally, tells you the expected letter when it mismatches, and normalizes formatting.

A correct control letter proves the string is well-formed — it does not prove the document exists or belongs to anyone. Identity documents are issued and verified by the Ministerio del Interior / Policía Nacional; when legal certainty matters, verify through official channels. Last verified: August 2026.

Published test vectors — each validated against the live tool: 12345678Z passes (12345678 mod 23 = 14 → letter 14 in TRWAGMYFPDXBNJZSQVHLCKE is Z) · X1234567L passes (X→0, 1234567 mod 23 = 19 → L) · 12345678A fails with the expected letter Z shown. Batch mode: paste one number per line and export per-row results as CSV. Last verified: 2026-08-12.

FAQ

How is the DNI letter computed?

Take the 8-digit number modulo 23 and read the letter at that position in TRWAGMYFPDXBNJZSQVHLCKE (position 0 = T). The official example from the Ministry of the Interior: 12345678 mod 23 = 14, and position 14 is Z, so the NIF is 12345678Z.

How does NIE validation differ?

Replace the leading letter before the math: X becomes 0, Y becomes 1, Z becomes 2. Then treat the result as a number and apply the same mod-23 table. Y1234567 is checked as 11234567, whose remainder is 10, giving X: Y1234567X. The prefix rule exists so that X1234567 and Y1234567 never share a control letter.

Which letters can never appear as the control letter?

I, Ñ, O and U. I and O look too much like 1 and 0, Ñ does not exist on most foreign keyboards, and U was dropped so that exactly 23 letters remain, 23 being a prime number. A number ending in one of those letters was transcribed wrongly.

Is the DNI the same as the NIF?

For Spanish citizens, yes: the tax identification number (NIF) of an individual is the DNI number followed by its control letter. For foreigners the NIF is their NIE. Company tax numbers (the former CIF, starting with a letter such as A or B) use a different check rule that this tool does not cover.

My DNI has only 7 digits. Is it invalid?

No. Numbers below 10 000 000 are written with a leading zero, for example 01234567X. Add the zero before checking; the letter is computed from the numeric value, so the zero does not change it.

Does a valid letter mean the document is real?

No. The letter proves only that the number was written correctly. It cannot tell whether the document exists, is current or belongs to the person presenting it; that requires the document itself or an official verification service.

Is my number uploaded when I check it?

No. The check is one modulo operation running in your browser. Nothing is transmitted or stored, which also makes batch-checking employee or customer lists safe.

Can I check a whole list of DNI/NIE numbers at once?

Yes. Open Batch check and paste one number per line; every row is validated locally with the same mod-23 rule and the result can be exported as CSV.

Last updated: