The Spain DNI / NIE Validator checks whether a Spanish personal identification number is structurally correct by re-running the official mod-23 control-letter algorithm and comparing the result to the letter you supplied. It works for both document types:
- DNI (Documento Nacional de Identidad) — issued to Spanish nationals.
Format: 8 digits followed by one control letter, e.g.
12345678Z. - NIE (Número de Identidad de Extranjero) — issued to foreign residents
in Spain. Format: a prefix letter (
X,Y, orZ) followed by 7 digits and one control letter, e.g.X1234567L.
The tool shows every step of the derivation — the numeric value used, the mod-23 remainder, the expected control letter, and whether it matches — so you can understand why a number passes or fails, not just that it does.
How the mod-23 algorithm works
The algorithm is defined in Spanish law (Real Decreto 1553/2005 for the DNI and the corresponding NIE regulations). The steps are:
-
For a NIE only: replace the leading letter with its numeric equivalent.
X → 0,Y → 1,Z → 2. This gives an 8-digit number identical in form to a DNI. -
Compute modulo 23 of that 8-digit integer. Because the number fits comfortably within a 32-bit integer, no big-number arithmetic is needed.
-
Look up the remainder (a value from 0 to 22) in the fixed table:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 T R W A G M Y F P D X B N J Z S Q V H L C K E -
The letter at that position must match the final character of the document. If it does, the document number is valid; if not, either the digits or the control letter contain a transcription error.
The table has exactly 23 entries and omits I, O, and U to prevent
mix-ups with the digits 1, 0, and a stylised v.
Example (fake numbers safe for testing)
| Input | Type | Numeric used | Remainder | Expected letter | Valid? |
|---|---|---|---|---|---|
00000000T | DNI | 0 | 0 mod 23 = 0 | T | Yes |
00000001R | DNI | 1 | 1 mod 23 = 1 | R | Yes |
00000000A | DNI | 0 | 0 mod 23 = 0 | T expected, A supplied | No |
X0000000T | NIE | 0 + 0000000 = 00000000 | 0 mod 23 = 0 | T | Yes |
X0000000X | NIE | 0 + 0000000 = 00000000 | 0 mod 23 = 0 | T expected, X supplied | No |
Y0000000Z | NIE | 1 + 0000000 = 10000000 | 10000000 mod 23 = 14 | Z | Yes |
These numbers are arithmetically constructed and do not correspond to any real person. Always use obviously-fake inputs (all zeros, sequential digits) in test suites and public documentation.
Privacy note
All validation is performed by JavaScript running in your browser tab. No document number, partial result, or timing signal is transmitted to any external server. The page contains no analytics hooks that capture form input. You can disconnect from the internet and the tool will continue to work exactly the same way.