Spain DNI/NIE Validator
Validate Spanish DNI (National ID) and NIE (Foreigner ID) — checks control letter using official algorithm.
DNI: Spain's national identity document
The DNI (Documento Nacional de Identidad) is the mandatory national identifier for Spanish citizens. It consists of 9 characters: 8 digits followed by a single check letter. It is issued by the Cuerpo Nacional de Policia under the Ministry of the Interior and is one of the most ubiquitous IDs in the European Union — every Spaniard older than 14 must hold one.
In addition to civil identification, the DNI doubles as a travel document throughout the Schengen Area: Spaniards can cross intra-EU borders with the card alone, no passport required. Since 2006 the document has carried an embedded chip with cryptographic keys (DNI electronico, eDNI), and the 2015 refresh introduced NFC contactless (DNI 3.0), turning the card into a hardware token for digital signatures and government services such as the Sede Electronica.
The check-letter algorithm
The verification letter is derived from the 8 numeric digits via a simple modulo 23 calculation. The remainder indexes into a fixed 23-character string:
letters = "TRWAGMYFPDXBNJZSQVHLCKE"
letter = letters[ digits mod 23 ]
The vowels I, O and U are deliberately omitted from the alphabet to avoid confusion with the digits 1, 0 and the letter V. Worked example: for digits 12345678, 12345678 mod 23 = 14, and letters[14] = "Z", so the full DNI is 12345678Z. The algorithm catches single-digit typos but, like any modular checksum, will not detect arbitrary substitutions that happen to land on the same residue class.
DNI vs NIE vs NIF: who gets what
Spain distinguishes three closely related identifiers:
- DNI — Spanish citizens only. Format:
8 digits + 1 letter. - NIE (Numero de Identidad de Extranjero) — foreigners with any legal status (residence, study, work, investment). Format:
X/Y/Z + 7 digits + 1 letter. The leading letter encodes the issuance batch (Xfor the oldest,Yfrom 2008,Zfrom 2025). - NIF (Numero de Identificacion Fiscal) — tax identifier. For Spanish individuals the NIF equals the DNI; for foreigners it equals the NIE; for legal entities (CIF historically) it is a letter + 7 digits + check digit.
The same check-letter algorithm validates both DNI and NIE — for NIE you first replace the leading letter with its numeric proxy (X = 0, Y = 1, Z = 2) and apply mod 23 to the resulting 8-digit number.
Where the DNI is required in Spain
- Voting and political participation in general, autonomous-community and municipal elections.
- Employment: contract signing, alta in Social Security, payroll.
- Healthcare: enrollment in the Sistema Nacional de Salud (SNS) and tarjeta sanitaria.
- Banking and KYC: opening accounts at BBVA, Santander, CaixaBank, ING.
- Real estate: notarized escrituras, mortgages, IBI registration.
- Travel: intra-Schengen movement; the DNI replaces the passport for citizens of the Schengen Area.
- Digital services: Cl@ve, AEAT (tax agency), Seguridad Social, autoescuela DGT — the eDNI chip authenticates without passwords.
eDNI 3.0 and the embedded chip
Since 2006 every DNI ships with a smartcard chip storing two RSA key pairs: one for authentication (proving identity) and another for qualified electronic signature under eIDAS, legally equivalent to a handwritten signature throughout the EU. The DNI 3.0, rolled out from 2015, added NFC, letting smartphones read the chip wirelessly via apps such as Cl@ve PIN, MiDNI and the Sede Electronica of the AEAT. The certificates expire every two and a half years and must be renewed at a police station.
Brazilian context: dual citizens and the DNI
Brazilians with Spanish citizenship — typically through descent from a grandparent under the Ley de Memoria Democratica — are entitled to and must hold a DNI once they reach 14 years of age. Brazilians without Spanish citizenship who reside in Spain (digital nomad visa, work permit, EU Blue Card, family reunification) instead receive an NIE. Both share the same modulo 23 validation, which is what this tool implements client-side. No data is sent to a server — the validation happens entirely in your browser.
FAQ
What is the difference between DNI and NIE? The DNI is reserved for Spanish citizens; the NIE is for foreigners. The 9-character format and the modulo 23 check-letter algorithm are nearly identical — the NIE prefixes with a letter (X/Y/Z) translated to a digit before the math.
Is the DNI mandatory in Spain? Yes, for everyone over 14 years old. Police and any public authority can request the DNI on the spot. Foreigners present a passport plus the NIE certificate (the green A4 sheet) or the TIE card.
Why are vowels missing from the check-letter alphabet? The string TRWAGMYFPDXBNJZSQVHLCKE omits I, O, U and the letter Ñ to avoid OCR and human confusion with digits (1, 0) and other letters (V).
Does the chip in the DNI really replace passwords? Yes. With a card reader (or NFC phone) and the personal PIN you receive at issuance, the eDNI signs documents and authenticates against public-administration portals with the same legal force as a handwritten signature.
Does this validator store my DNI? No. The arithmetic runs in JavaScript in your browser; no HTTP request transmits the digits and the page does not log them.
Related Tools
CPF Validator
Validate Brazilian CPF numbers instantly using the official algorithm. Useful for testing document validation in applications. No data sent to servers.
Batch CPF Validator
Validate a list of CPFs (one per line) and see which are valid and which are not. No data sent to servers.
Batch CNPJ Validator
Validate a list of CNPJs (one per line) with a summary of valid, invalid and total. No data sent to servers.