Spanish NIE number generator (X, Y, Z with check letter)

A valid NIE (Spain's foreigner identity number) has an X, Y or Z prefix, 7 digits and a check letter. To calculate the letter, the prefix is replaced with 0, 1 or 2 and the DNI's mod 23 rule is applied. NIEs generated by DataMockSeed are fake: they pass validation, but identify no real foreign resident.

The NIE replaces the X, Y or Z prefix with 0, 1 or 2 and applies the same mod 23 calculation as the DNI to get the check letter.

5 generated examples
Y5506303WValid
X1312273PValid
X1145082GValid
X5966646DValid
Z8381407MValid

How it's calculated

X/Y/Z prefix (equivalent to 0/1/2) + 7 digits + check letter, same calculation as the DNI.

Generated sample
Y5506303W

The X/Y/Z prefix is replaced by 0/1/2 and the rest follows the same calculation as the DNI.

  1. 1
    Prefix → equivalent digit
    Y → 1
  2. 2
    Full number (prefix + 7 digits)
    15506303
  3. 3
    Remainder of number ÷ 23
    2
  4. 4
    Letter at the remainder's position
    W

Frequently asked questions

What is the difference between the NIE and the DNI?

The NIE identifies foreign residents in Spain and has an X, Y or Z prefix before 7 digits; the DNI has 8 digits. The check letter of both is calculated with the same mod 23 rule.

Are the X, Y and Z prefixes equally common?

No. In real life, X and Y are much more common than Z. The NIE generator does not enforce that ratio and lets you pick any prefix from the full generator.

Can I use a generated NIE to sign up test users?

Yes. A generated NIE has the same format and check letter that a real form requires, without using the data of an existing person.

Keep exploring

Looking for more data types? Try the full generator.