Data

Spanish DNI Validator

Verify Spanish identity documents in real-time. Validate DNI and NIE with official letter algorithm.

Instant🔒In your browserNo signup
Live
Try with:

What is the Spanish DNI?

The Documento Nacional de Identidad (DNI) is the official identification document for Spanish citizens, issued by the National Police since 1944. It consists of 8 numeric digits followed by a check letter calculated through a mathematical algorithm.

The DNI is mandatory for all Spaniards over 14 years old and serves as a travel document within the European Union. Its unique format enables automatic validation without needing to consult official databases, simply by verifying that the letter matches the digits.

In addition to the DNI, there's the NIE (Número de Identidad de Extranjero) which follows the same algorithm but starts with the letters X, Y, or Z. Both documents are essential for administrative, banking, employment, and tax procedures in Spain.

How the letter algorithm works

The DNI letter calculation uses a modulo 23 algorithm established by the Spanish Ministry of the Interior:

  • The 8 DNI digits are taken as a whole number
  • The remainder of dividing that number by 23 is calculated
  • The result (0-22) is mapped to a letter according to the official table: TRWAGMYFPDXBNJZSQVHLCKE
  • That letter must match the DNI letter

For example, for DNI 12345678: 12345678 ÷ 23 = 536768 with remainder 14. Position 14 in the table is letter Z, so the complete DNI is 12345678Z.

For NIE, the initial letters X, Y, Z are replaced by 0, 1, 2 respectively before calculation. This system detects transcription errors with very high precision and is impossible to forge without knowing the algorithm.

When and why to validate a DNI

DNI validation is critical in multiple legal and commercial contexts in Spain:

  • Digital onboarding: banks, fintech, and telecoms must validate DNI during customer registration to comply with KYC regulations and fraud prevention
  • E-commerce: online stores verify DNI for high-value purchases or shipments to addresses different from billing
  • Human resources: companies validate candidate DNIs before hiring, avoiding administrative errors with Social Security
  • Online public procedures: electronic administration portals (Cl@ve, Sede Electrónica) require valid DNI to access services

Validating before sending data to backend systems reduces server load and improves user experience. A usability study shows that detecting DNI errors in real-time reduces form abandonment by 23%.

Limitations and common mistakes

This validator checks the mathematical coherence of the DNI, but has legal limitations:

  • Does not verify validity: a DNI can be format-valid but expired (Spanish DNIs are valid for 5-10 years depending on age)
  • Does not confirm ownership: cannot verify that the DNI belongs to the person entering it
  • Does not detect reported documents: if a DNI was reported as stolen, its format remains correct
  • Format sensitive: some systems expect a hyphen (12345678-Z) while others reject it

Common errors: confusing similar letters (O/0, I/1), using lowercase letters in systems requiring uppercase, or entering NIE without specifying the initial letter. For official verifications, always use the Ministry's @Firma platform or identity verification services approved by SEPBLAC.

FAQ

Can I validate NIE with this tool?

Yes. The NIE (Foreigner Identity Number) uses the same algorithm as the DNI. The initial letters X, Y, or Z are converted to 0, 1, 2 respectively, and then the same final letter calculation is applied.

Why does my correct DNI appear as invalid?

Check that there are no spaces at the beginning or end, that the letter is uppercase, and that you're not confusing similar characters (O with 0, I with 1). If the physical DNI has those numbers and letter, the problem may be a transcription error.

Is it legal to validate other people's DNIs?

Mathematical format validation is legal. But storing, processing, or sharing others' DNIs without explicit consent violates the European GDPR and Spanish LOPDGDD. Only validate DNIs when you have a legal basis (contract, consent, legal obligation).

What is the TRWAGMYFPDXBNJZSQVHLCKE table?

It's the official sequence of 23 letters used by the Ministry of the Interior to assign check letters. Each position (0-22) corresponds to the remainder of division by 23. It's not arbitrary: it was designed to maximize differences between consecutive letters and avoid confusion.

Was this generator useful?