Skip to main content

Spain NIE Validator

Online validator for Spanish NIE numbers. Verifies structure, prefix, and check letter integrity.

How does Spain NIE validation work?

The validator removes punctuation, confirms the structure (prefix X, Y, or Z + 7 digits + 1 letter), and calculates the Modulo 23 checksum.

The prefix letter is converted to its numerical value (X=0, Y=1, Z=2) to form an 8-digit base, and the remainder modulo 23 is matched against TRWAGMYFPDXBNJZSQVHLCKE.

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