Spanish NIE: what it is and how to test it
The NIE (Número de Identidad de Extranjero) is the identification number of foreigners in Spain, used for taxes, work, rent and bank accounts. It looks like the DNI with a letter in front, and the control letter is computed the same way after the first letter is turned into a digit.
For tests only. These numbers have a correct format and check digit but belong to no real person or account. Never use them to deceive, to open accounts or to bypass a check. The numbers on this page come from the same generator as the tool, with a fixed seed so that the examples do not change; the tool creates new ones at every click.
Structure of the number
9 characters: the letter X, Y or Z, 7 digits and a control letter, written X1234567L. The initial X was used first, then Y, and Z from 2008 on.
The check digit, step by step
Replace the initial letter with a digit (X = 0, Y = 1, Z = 2), write it before the 7 digits to get an 8-digit number, divide by 23 and take the letter at the position of the remainder in the table TRWAGMYFPDXBNJZSQVHLCKE: the same as the DNI.
Worked example with X2301127T:
The initial X becomes 0, so the number is 2301127; 2301127 divided by 23 leaves 0; position 0 of the letter table is "T".
X=0 Y=1 Z=2Valid examples
Five numbers generated by the tool with a fixed seed, each one accepted by its validator:
| Without mask | Validator |
|---|---|
X2301127T | valid |
Y2229942Z | valid |
Y6586234Z | valid |
Z1625937A | valid |
Y0834163J | valid |
How the validator answers
The same first example, one with a changed ending and one truncated, checked by the validator:
| Value | Result | Reason |
|---|---|---|
X2301127T | valid | - |
X2301127U | invalid | the check digit should be T |
X230112 | invalid | wrong format: X, Y or Z, 7 digits and a letter |
Common mistakes
- Forgetting to convert the initial letter is the usual bug: validating "X1234567" as if X were a digit, or dropping it, gives the wrong letter.
- Initials other than X, Y and Z are not NIE: an old validator that only accepts X will reject all the recent Z numbers.
Frequently asked questions
What is the difference between NIE and NIF?
The NIF is the tax number: for Spaniards it is the DNI, for foreigners it is the NIE. The NIE is the identity number of foreigners; its control letter works like the DNI's.
Can a generated NIE be used to rent or open an account?
No. It has the correct format and letter but was never issued to anyone, so it is only useful to test forms and validations.
Can I use a Spanish NIE number generated here in a real system?
No. A number such as X2301127T has a correct format and check, but nobody was issued it, and it may coincide with a real holder by chance. Use it in test environments, demos and automated tests that never leave your control.