Spain DNI / NIE Validator

Verify a Spanish DNI or NIE in one click — control letter, mod-23 algorithm explained.

Ad placeholder (leaderboard)
Enjoying the tools? Go Pro for £4.99 (one-time) and remove all ads — forever, on this device. Remove ads — £4.99

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, or Z) 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:

  1. 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.

  2. Compute modulo 23 of that 8-digit integer. Because the number fits comfortably within a 32-bit integer, no big-number arithmetic is needed.

  3. Look up the remainder (a value from 0 to 22) in the fixed table:

    012345678910111213141516171819202122
    TRWAGMYFPDXBNJZSQVHLCKE
  4. 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)

InputTypeNumeric usedRemainderExpected letterValid?
00000000TDNI00 mod 23 = 0TYes
00000001RDNI11 mod 23 = 1RYes
00000000ADNI00 mod 23 = 0T expected, A suppliedNo
X0000000TNIE0 + 0000000 = 000000000 mod 23 = 0TYes
X0000000XNIE0 + 0000000 = 000000000 mod 23 = 0T expected, X suppliedNo
Y0000000ZNIE1 + 0000000 = 1000000010000000 mod 23 = 14ZYes

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.

Ad placeholder (rectangle)