Spain’s personal tax and identity numbers all share a 9-character format with a final control letter: the DNI for citizens, the NIE for foreigners, and the NIF (which, for an individual, is simply their DNI or NIE). This validator detects the document type automatically and confirms whether the control letter is correct.
How it works
The control letter is a single modulo-23 checksum:
- Get the numeric part. A DNI uses its 8 digits directly. A NIE first maps its leading letter — X → 0, Y → 1, Z → 2 — and prepends that to the following 7 digits to form an 8-digit number.
- Take modulo 23. Compute
number mod 23, giving a remainder from 0 to 22. - Look up the letter. Index into the table
TRWAGMYFPDXBNJZSQVHLCKE. The letter at that position must equal the document’s final character.
The letters I, O, U and Ñ are intentionally absent to avoid confusion with digits and similar-looking characters.
Example
For DNI number 12345678:
- 12,345,678 mod 23 = 14
- Position 14 in
TRWAGMYFPDXBNJZSQVHLCKEis Z
So the valid DNI is 12345678Z. For the NIE X1234567, the X becomes 0 giving 01234567, then 01234567 mod 23 = 10, which maps to L, so X1234567L is valid.
| Type | Format | Example |
|---|---|---|
| DNI | 8 digits + letter | 12345678Z |
| NIE | X/Y/Z + 7 digits + letter | X1234567L |
It runs entirely in your browser, so the ID number you type is never uploaded. A structurally valid number is not guaranteed to be one that has actually been issued.