Spain NIF/NIE Validator

Validate a Spanish NIF or NIE with the official modulo-23 letter table

Ad placeholder (leaderboard)

A Spanish NIF (Número de Identificación Fiscal) is the tax ID of Spanish citizens — the DNI number plus a single control letter. Foreign residents instead carry a NIE (Número de Identidad de Extranjero), which begins with X, Y or Z. Both use the same modulo-23 check letter. This free validator runs that exact algorithm in your browser, which is handy for HR onboarding, KYC checks and form validation.

How it works

  1. Detect the type. If the value starts with X, Y or Z it is a NIE; if it starts with a digit it is a NIF.
  2. Build the number. For a NIE, replace the leading letter with a digit: X → 0, Y → 1, Z → 2, then append the remaining 7 digits to get an 8-digit number. A NIF already has 8 digits.
  3. Modulo 23. Compute number mod 23. The remainder is 022.
  4. Look up the letter. Index into the fixed table TRWAGMYFPDXBNJZSQVHLCKE. The letter at that position is the correct control letter.
  5. Compare. The NIF/NIE is valid if the computed letter equals the supplied final letter (the letters I, O, U and Ñ are intentionally excluded from the table).

Example

Validate 12345678Z: 12345678 mod 23 = 14. The 14th character (0-indexed) of TRWAGMYFPDXBNJZSQVHLCKE is Z, which matches — so the NIF is valid.

For X1234567L: X → 0, giving 01234567. 1234567 mod 23 = 10, and position 10 is L, which matches — the NIE is valid.

Notes

A correct control letter confirms the identifier is internally consistent, not that it belongs to a real, registered individual. CIF numbers (for companies) use a different algorithm and are not covered here. Everything runs locally — the identifier never leaves your browser.

Ad placeholder (rectangle)