DNI & NIE Validator
ValidatorValidate Spanish DNI and NIE numbers instantly. Checks the Mod 23 check letter for both document types. Free, runs in your browser.
Enter 9 characters: DNI (8 digits + letter) or NIE (X/Y/Z + 7 digits + letter). Case is ignored.
The check letter is computed as: letter = "TRWAGMYFPDXBNJZSQVHLCKE"[number % 23]. For NIE, X is treated as 0, Y as 1, and Z as 2 before computing the modulus.
About this tool
About DNI & NIE Validator
This validator checks both Spanish DNI (Documento Nacional de Identidad) and NIE (Número de Identificación de Extranjero) numbers using the official Mod 23 algorithm. Enter any 9-character document number and the tool instantly determines whether the check letter is correct — no network request needed.
The validator auto-detects document type: a string starting with 8 digits followed by a letter is treated as DNI; a string starting with X, Y, or Z followed by 7 digits and a letter is treated as NIE. For NIE, the prefix letter is converted to its numeric equivalent (X=0, Y=1, Z=2) before computing the modulus. The validator reports the document type, the numeric body, the check letter, and a clear error message when validation fails.
Use this validator to verify DNI and NIE numbers collected from users before processing them in your backend, to debug why a number is failing validation in your system, or to manually check a document number for correctness. It's also useful for understanding the check letter algorithm itself.
Instant validation with no network requests — all computation runs locally in the browser. The validator handles spaces, hyphens, and mixed case, normalising the input before checking. It provides precise error messages (wrong check letter vs. wrong format) so you can pinpoint exactly what is wrong.
Key Features
- Validates both DNI (citizens) and NIE (foreign nationals)
- Official Mod 23 check letter algorithm
- Auto-detects document type from input
- Normalises spaces, hyphens, and case
- Shows type, number body, and check letter
- Precise error messages for each failure mode
- 100% browser-based, no data sent
FAQ
DNI / NIE Validator — Frequently Asked Questions
How does the DNI check letter work?
The check letter is determined by taking the 8-digit number modulo 23 and looking up the result in the table 'TRWAGMYFPDXBNJZSQVHLCKE' (index 0–22). For example: 12345678 % 23 = 14 → letter 'Z'. The letter is chosen to detect transcription errors — any single digit change or letter swap will almost always produce a different check letter.
How does NIE validation differ from DNI?
NIE numbers start with X, Y, or Z. Before computing the check letter, the prefix letter is replaced with its numeric equivalent: X→0, Y→1, Z→2. The result is then treated as an 8-digit number and the Mod 23 algorithm is applied identically to DNI. So X1234567 becomes 01234567, then 01234567 % 23 = 20 → letter 'E'.
What does 'invalid check letter' mean?
It means the numeric body of the document is correct in format (right length and digit/letter pattern), but the last character does not match the expected Mod 23 result. This usually indicates a typo in the last character — or anywhere in the number, since any digit change will change the expected letter. Double-check that you entered the number exactly as printed on the document.
Can this validator be used to check if a DNI belongs to a real person?
No. This tool only validates the mathematical structure of the check letter. A number can be format-valid (correct check letter) but not registered with the Spanish authorities. To verify whether a specific DNI is issued to a real individual, you would need access to official government databases — something no public tool can provide.
Tips
- Hyphens and spaces are stripped automatically — enter the number with or without them
- Lowercase letters are accepted — the validator converts to uppercase before checking
- Use the 'DNI' and 'NIE' example buttons to load sample valid numbers
- The DNI Generator tool on this site creates random valid DNIs for test data