Skip to main content

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:

PositionFieldLengthMeaning & RuleExample
1Initial Letter1 letterChronological resident series: X (value 0), Y (value 1), or Z (value 2)Y
2 to 8Sequential7 digitsSequential file number in Central Foreigners Registry1234567
9Control Letter1 letterLetter calculated with Modulo 23 on the 8-digit substituted numberB

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. 1. Replace initial letter with numeric prefix: X = 0, Y = 1, Z = 2.
  2. 2. Prepend prefix to the 7 numeric digits, creating an 8-digit integer.
  3. 3. Compute integer remainder: Remainder = Number % 23.
  4. 4. Lookup character in TRWAGMYFPDXBNJZSQVHLCKE.
  5. 5. Verify match with the 9th character.

Frequently Asked Questions (FAQ)