Home DNI / NIE Spain

Spain DNI / NIE validator

How the DNI / NIE format works

Format
8 digits + 1 check letter (DNI), or X/Y/Z + 7 digits + 1 check letter (NIE)
Example
12345678Z

Things to watch for

  • The final letter is a mod-23 check derived from the digits, not a random suffix
  • Checksum only — a matching letter does not confirm the DNI/NIE is actually issued or active
  • NIE numbers map their leading X/Y/Z letter to a digit (0/1/2) before the same mod-23 check is applied
Regex for DNI / NIE
^([0-9]{8}[A-Z]|[XYZ][0-9]{7}[A-Z])$

A DNI (Documento Nacional de Identidad) is Spain’s national identity number, issued by the Dirección General de la Policía to Spanish citizens; the NIE (Número de Identidad de Extranjero) is the parallel number issued to foreign residents. Both sit under the broader NIF (Número de Identificación Fiscal) umbrella used for tax purposes. A DNI is 8 digits followed by a single check letter, for example 12345678Z; an NIE swaps the leading digit for X, Y, or Z and otherwise follows the same shape, for example X1234567L.

The check letter isn’t an arbitrary suffix — it’s derived by taking the 8-digit number modulo 23 and using the result as an index into a fixed 23-letter reference string that never changes. For an NIE, the leading X/Y/Z is first converted to 0/1/2 before that same calculation runs. Because the letter is mathematically tied to the digits, a single mistyped digit almost always produces a letter mismatch, which is exactly what this check catches before a form gets rejected.

How this validator works

This tool checks that the input matches the DNI or NIE shape and recomputes the mod-23 letter from the digits entirely in your browser — nothing is sent to a server, and there’s no signup.

What a pass doesn’t tell you

A matching check letter confirms the number is internally consistent, not that it was actually issued, that it belongs to a real person, or that it’s currently active. Only the Dirección General de la Policía can confirm a DNI or NIE is genuinely on file.

Scope: this page covers DNI/NIE format and check-letter validation only — not identity verification or residency status.

Content last reviewed 2026-07-22.

DNI / NIE FAQ

What's the difference between DNI, NIE, and NIF?

DNI is issued to Spanish citizens and NIE to foreign residents — both are personal ID numbers built on the same check-letter structure. NIF is the umbrella term for Spain's tax identification number, and for most individuals your DNI or NIE simply doubles as your NIF.

How is the check letter on a DNI or NIE calculated?

The 8-digit number is divided by 23, and the remainder picks a letter from a fixed 23-character reference string used nationwide. An NIE first converts its leading X, Y, or Z to 0, 1, or 2 so the same calculation applies to the resulting number.

Does a valid check letter mean my DNI or NIE is real?

No. It confirms the letter is mathematically consistent with the digits — not that the document was ever issued or is currently valid. Only the Dirección General de la Policía can confirm that.

← More DNI / NIE validators