Spain NIE Generator
Generate and format valid Spanish NIE (Foreigner Identity Number) for development and testing.
Waiting for generation...
About Spain NIE
The NIE (Número de Identidad de Extranjero) is the personal and tax identification code issued by the Dirección General de la Policía (DGP) for resident foreigners and non-citizens with economic interests in Spain.
The NIE consists of 9 characters: 1 initial prefix letter (X, Y, or Z), 7 digits, and 1 control letter. For Modulo 23 calculation, X equals 0, Y equals 1, and Z equals 2.
Anatomy & Structure of Spanish NIE
The Foreigner Identity Number (NIE) consists of 9 alphanumeric characters:
| Position | Field | Length | Meaning & Rule | Example |
|---|---|---|---|---|
| 1 | Initial Letter | 1 letter | Chronological resident series: X (value 0), Y (value 1), or Z (value 2) | Y |
| 2 to 8 | Sequential | 7 digits | Sequential file number in Central Foreigners Registry | 1234567 |
| 9 | Control Letter | 1 letter | Letter calculated with Modulo 23 on the 8-digit substituted number | B |
NIE Validation Algorithm (Modulo 23 with X/Y/Z Mapping)
Validation converts the initial letter to a numeric digit before applying modulo 23:
Letter = "TRWAGMYFPDXBNJZSQVHLCKE"[(Map(Letter) + 7_digits) % 23]
- 1. Replace initial letter with numeric prefix: X = 0, Y = 1, Z = 2.
- 2. Prepend prefix to the 7 numeric digits, creating an 8-digit integer.
- 3. Compute integer remainder: Remainder = Number % 23.
- 4. Lookup character in TRWAGMYFPDXBNJZSQVHLCKE.
- 5. Verify match with the 9th character.
Frequently Asked Questions (FAQ)
How is the NIE control letter calculated?
The initial letter is converted to a digit (X=0, Y=1, Z=2), creating an 8-digit number. The remainder of division by 23 determines the letter in TRWAGMYFPDXBNJZSQVHLCKE.
Are the generated NIE numbers real?
No. All numbers are fictitious and generated according to official specifications strictly for development and QA testing.
What prefixes are valid for NIE?
Official prefixes are X (records before 2008), Y (records before 2020), and Z (recent registrations).