Spanish DNI: what it is and how to test it
The DNI (Documento Nacional de Identidad) is the identity number of Spanish citizens: 8 digits and a control letter. The same number with a letter is the NIF used for taxes. Registration forms, banks and public portals validate the letter, which makes it one of the most common test cases in Spain.
For tests only. These numbers have a correct format and check digit but belong to no real person or account. Never use them to deceive, to open accounts or to bypass a check. The numbers on this page come from the same generator as the tool, with a fixed seed so that the examples do not change; the tool creates new ones at every click.
Structure of the number
9 characters: 8 digits followed by a letter, written 12345678Z. The letter is not chosen: it is calculated from the digits.
The check digit, step by step
Divide the 8-digit number by 23 and keep the remainder. The remainder is the position, counted from 0, in the fixed table TRWAGMYFPDXBNJZSQVHLCKE, and the letter at that position is the control letter. There are 23 letters because the letters I, Ñ, O and U are left out, to avoid confusion with digits and with each other.
Worked example with 66414922F:
66414922 divided by 23 leaves 7; position 7 of the letter table is "F".
0=T 1=R 2=W 3=A 4=G 5=M
6=Y 7=F 8=P 9=D 10=X 11=B
12=N 13=J 14=Z 15=S 16=Q 17=V
18=H 19=L 20=C 21=K 22=EValid examples
Five numbers generated by the tool with a fixed seed, each one accepted by its validator:
| Without mask | Validator |
|---|---|
66414922F | valid |
52383050K | valid |
65209706Z | valid |
66620335F | valid |
48395236Q | valid |
How the validator answers
The same first example, one with a changed ending and one truncated, checked by the validator:
| Value | Result | Reason |
|---|---|---|
66414922F | valid | - |
66414922G | invalid | the check digit should be F |
6641492 | invalid | wrong format: 8 digits and a letter |
Common mistakes
- Numbers shorter than 8 digits must be padded with zeros on the left before dividing (the DNI 1234567 is 01234567); skipping this changes the number and the letter.
- Lowercase and spaces ("1234 5678 z") are accepted by people but not always by forms: normalise to upper case without separators before validating.
Frequently asked questions
How do I calculate the letter of a DNI?
Divide the 8 digits by 23 and look up the remainder in the table TRWAGMYFPDXBNJZSQVHLCKE: 12345678 leaves 14 and the letter at position 14 is Z, so the DNI is 12345678Z.
Is the NIF the same as the DNI?
For a Spanish citizen, yes: the NIF is the DNI number with its letter. Foreigners use the NIE, which has its own prefix and a page in this family.
Can I use a Spanish DNI number generated here in a real system?
No. A number such as 66414922F has a correct format and check, but nobody was issued it, and it may coincide with a real holder by chance. Use it in test environments, demos and automated tests that never leave your control.