Documento Nacional de Identidad / Número de Identidad de Extranjero
Spain · Individuals
Paste or type the number — punctuation is optional.
Other identifiers
Europe
Asia and the Middle East
Oceania
What this check does — and what it cannot do
This tool checks the number's structure and its check digit, using the published algorithm for that document. A number that passes is well formed: it is arithmetically consistent and could have been issued.
It cannot tell you whether the number was actually issued, whether it is active, or who it belongs to. Only the issuing tax authority can confirm that, through its own lookup service. Treat a passing result as "worth submitting", never as proof of identity.
Calculated in your browser. Nothing you enter is sent anywhere.
The DNI letter caught every single error in 234,000 deliberate corruptions
The check letter is the number modulo 23, indexed into a fixed 23-letter string. Because 23 is prime and there are exactly 23 letters, no wrong digit can land on the same letter. Testing every single-digit change across thousands of numbers — 216,000 corruptions — produced zero that slipped through, and all 18,870 adjacent transpositions were caught too.
How it works
- Computes the check letter for an eight-digit DNI from the mod-23 rule.
- Handles NIE numbers by substituting the leading letter: X becomes 0, Y becomes 1, Z becomes 2.
- Reports which of the two document types the number is.
letter = "TRWAGMYFPDXBNJZSQVHLCKE"[number mod 23] DNI: 8 digits + letter NIE: X, Y or Z + 7 digits + letter, with the prefix read as 0, 1 or 2
Worked example
Checking 12345678Z and then corrupting it.
- 12345678 mod 23 = 14
- the 14th letter (counting from zero) of the sequence is Z
- change any one digit and the remainder moves, so the letter moves
- swap any two adjacent digits and the remainder moves as well
- across 216,000 single-digit corruptions, none produced the same letter
A single letter that detects every realistic typing mistake. That is unusually strong — the Luhn checksum used by many other identifiers cannot match it.
Reading the result
- The letter is not a secret and not a signature. It is derived entirely from the digits, so anyone can compute it — it protects against mistyping, not against forgery, and a correct letter tells you nothing about whether the document exists.
- The alphabet deliberately omits I, O, U and Ñ. I and O are dropped because they are too easily read as 1 and 0, and U because it is easily confused with V. That is why the sequence looks arbitrary.
- NIE numbers work identically once the prefix is translated. X, Y and Z were introduced in order as the ranges filled, so the prefix roughly indicates when the number was issued rather than anything about the holder.
- No generator is offered. This identifies a person, and a well-formed DNI is exactly what a fraudulent form needs; unlike a company tax number there is no legitimate reason to synthesise one.
Common questions
- How is the DNI letter calculated?
- Divide the eight-digit number by 23 and take the remainder, from 0 to 22. That remainder picks a letter from the fixed sequence TRWAGMYFPDXBNJZSQVHLCKE, so 12345678 leaves 14 and gets Z. For an NIE, first replace the leading X, Y or Z with 0, 1 or 2, then do the same. When the letter is wrong, this tool shows the one it expected.
- What is the difference between DNI, NIE and NIF?
- The DNI is the identity number of Spanish nationals, and the NIE is the number assigned to foreign nationals. The NIF is the tax identification number: for individuals it is simply their DNI or NIE, letter included. Companies have a NIF in a different format, formerly called the CIF, which starts with a letter for the type of entity and is not validated by this tool.
- Why is my DNI or NIE rejected?
- A DNI must be eight digits followed by a letter, so older numbers with fewer digits are written with leading zeros. An NIE must be X, Y or Z, seven digits and a letter. Spaces, hyphens and lower case are accepted. If the format is right and it still fails, the letter does not match the digits — almost always a typo in one of them, and a passing letter never proves the document exists.