Spanish NIE/NIF Validator

This Spanish NIE/NIF validator checks a citizen NIF (8 digits + letter) or a foreign-resident NIE (letter + 7 digits + letter) against the official mod-23 letter checksum. Everything runs in your browser.

How to use it

Paste the number with or without spaces, in either format. The tool detects which one you entered automatically and applies the matching checksum calculation.

How the mod-23 checksum works

The 8-digit numeric portion is divided by 23, and the remainder (0–22) is used as an index into the fixed reference string TRWAGMYFPDXBNJZSQVHLCKE — the letter at that position is the correct check letter. For a NIE, the leading X, Y, or Z is first replaced with 0, 1, or 2 respectively to form the 8-digit number used in the same calculation.

Why this catches typos reliably

Because the check letter is a deterministic function of all 8 numeric digits, transposing or mistyping any single digit almost always produces a different remainder — and therefore a different, mismatching letter. This is the same property that makes checksums useful for catching data-entry errors before they reach a form or database.

Spanish NIE/NIF Validator Pro

Pro version coming soon — batch validation via CSV upload, exportable results, API access, and an offline version. The free tool stays free.

Pro version coming soon

Batch validation via CSV upload, exportable results, API access, and an offline version are on the way. The free tool stays free.

Frequently asked questions

What's the difference between a NIF and a NIE?

A NIF (Número de Identificación Fiscal) is the tax ID for Spanish citizens: 8 digits plus a check letter. A NIE (Número de Identidad de Extranjero) is the equivalent for foreign residents: a leading letter (X, Y, or Z), 7 digits, and a check letter.

How is the check letter calculated?

The numeric part is taken modulo 23, and the remainder indexes into the fixed string "TRWAGMYFPDXBNJZSQVHLCKE" to get the check letter. For a NIE, the leading letter is first converted to a digit (X→0, Y→1, Z→2) and prepended to the 7 digits before the same calculation.

Why does a NIE need the leading letter converted first?

NIE numbers were introduced after NIF and needed to avoid colliding with the existing NIF number space, so the leading X/Y/Z letter effectively extends the numeric range — X0000000 through Z9999999 — before the same mod-23 formula applies.

Does this tool check CIF numbers (for companies)?

No. CIF (Código de Identificación Fiscal), used for businesses, uses a different checksum algorithm entirely — a weighted Luhn-style sum with a letter-or-digit control character depending on the entity type. That's out of scope for this tool.

Is my NIF/NIE sent anywhere when I use this tool?

No. The checksum is computed entirely in your browser via JavaScript. Nothing is transmitted, logged, or stored.