Generator · Spanish data
Spanish NIE
Endpoint GET /v1/es/nie
What it covers
Returns a valid Spanish NIE (foreigner identity number): an `X`/`Y`/`Z` prefix, 7 digits, and a correct control letter. Set `invalid=true` for a NIE with a deliberately wrong control letter.
How it’s calculated
The NIE control letter is the Spanish DNI mod-23 check character: replace the X/Y/Z prefix with 0/1/2, prepend it to the 7-digit body to form an 8-digit number, take number mod 23, and index the 23-letter alphabet TRWAGMYFPDXBNJZSQVHLCKE.
Algorithm
- Start from the NIE body: a prefix letter (one of X, Y, Z) and exactly 7 body digits.
- Substitute the prefix with a digit: X->0, Y->1, Z->2. Concretely, prefixValue = index of the prefix in the string "XYZ" (X=0, Y=1, Z=2).
- Form an 8-digit numeric string by concatenating that prefixValue digit in front of the 7 body digits, then parse it as an integer N. (E.g. prefix Y + body 1234567 -> "1"+"1234567" = "11234567", N = 11234567.)
- Compute the remainder R = N mod 23. R is in the range 0..22.
- Index the control alphabet ALPHABET = "TRWAGMYFPDXBNJZSQVHLCKE" (23 characters, 0-indexed) at position R. The character at that position is the control letter.
- The full NIE is prefix + 7 body digits + control letter (9 characters total).
Worked example
NIE Y1234567?
Prefix Y -> prefixValue = indexOf('Y') in "XYZ" = 1.
Prepend to body 1234567: numeric string = "1" + "1234567" = "11234567", so N = 11234567.
N mod 23: 23 * 488459 = 11234557; 11234567 - 11234557 = 10, so R = 10.
ALPHABET = "TRWAGMYFPDXBNJZSQVHLCKE"; position 10 (0-indexed) = T(0) R(1) W(2) A(3) G(4) M(5) Y(6) F(7) P(8) D(9) X(10) -> 'X'.
Control letter = X.The control letter is X, giving the full NIE Y1234567X.
Edge cases
- The prefix is limited to X, Y, Z. Historically X was assigned first, then Y, and now Z; each maps to substitute digit 0, 1, 2 respectively before the mod-23 computation.
- The generator draws the first body digit in the range 1-9 (no leading zero) for the common shape, though a leading zero is still mathematically valid since the numeric value is what feeds the mod-23 step.
Gotchas
- The check character is a LETTER, not a digit — it is the mod-23 residue mapped through the fixed non-alphabetical alphabet TRWAGMYFPDXBNJZSQVHLCKE, so you cannot just append the remainder as a number.
- The modulus is applied to the full 8-digit number formed AFTER substituting the prefix letter with its digit — you must prepend the 0/1/2 substitute, not run mod-23 on the 7 body digits alone.
- The control alphabet is shared with the DNI; the only NIE-specific step is the X/Y/Z -> 0/1/2 prefix substitution.
Parameters
| Parameter | Type | Description |
|---|---|---|
| count | integer1–1000 | Number of records to return, 1–1000 (your plan may lower this). Omitted returns a single record; set it for a batch. |
| edge | boolean | Restrict output to valid edge-case NIEs from the rare corners. |
| extreme | boolean | Return a correct value wrapped in a hostile encoding (untrimmed whitespace, invisible/zero-width characters, BOM, or bidi/combining marks). Homoglyphs are excluded so the value stays machine-parseable; it still validates after normalisation. |
| invalid | boolean | Return a NIE with a deliberately wrong control letter. |
| seed | integer | Integer seed for reproducible output: the same seed always yields the same record. |
Response fields
| Field | Type | Description |
|---|---|---|
| value | string | The full NIE: prefix + 7 digits + control letter. |
| prefix | string | The prefix letter, one of `X`, `Y`, `Z`. |
| digits | string | The 7-digit body, leading zeros preserved. |
| letter | string | The single control letter from `TRWAGMYFPDXBNJZSQVHLCKE`. |
Other generators for Spain
Spanish CIFSpanish companySpanish company nameSpanish DNISpanish email addressSpanish IBANSpanish personSpanish person nameSpanish product or service offeringSpanish vehicle registration plate
See all generators for Spain →The same kind of identifier elsewhere
Austrian data · Austrian SVNRBelgian data · Belgian RijksregisternummerBulgarian data · Bulgarian EGNCroatian data · Croatian JMBGCroatian data · Croatian OIBCypriot data · Cyprus TICCzech data · Czech rodné čísloDanish data · Danish CPRDutch data · Dutch BSNEstonian data · Estonian isikukoodFinnish data · Finnish henkilötunnusFinnish data · Finnish Y-tunnusFrench data · French NIRGerman data · German Steuer-IdNrGreek data · Greek AFMGreek data · Greek AMKAHungarian data · Hungarian adóazonosító jelHungarian data · Hungarian személyi azonosítóHungarian data · Hungarian TAJIrish data · Irish PPSNItalian data · Italian Codice FiscaleLatvian data · Latvian personas kodsLithuanian data · Lithuanian asmens kodasLuxembourg data · Luxembourg matriculePolish data · Polish PESELPortuguese data · Portuguese NIFRomanian data · Romanian CNPSlovak data · Slovak rodné čísloSlovenian data · Slovenian davčna številkaSlovenian data · Slovenian EMŠOSwedish data · Swedish personnummer
Try it