Spain DNI Generator
Generate and format valid Spanish DNI (National Identity Card) numbers for development and testing.
Waiting for generation...
About Spain DNI
The Documento Nacional de Identidad (DNI) is the official identity card issued by the Dirección General de la Policía (DGP) for Spanish citizens. For tax purposes (AEAT), the DNI number serves as the individual tax code (NIF).
The DNI consists of 8 digits followed by 1 control letter calculated via the official Modulo 23 algorithm with the 23-character table TRWAGMYFPDXBNJZSQVHLCKE.
Anatomy & Structure of Spanish DNI
The Documento Nacional de Identidad (DNI) consists of 9 standardized characters:
| Position | Field | Length | Meaning & Rule | Example |
|---|---|---|---|---|
| 1 to 8 | Sequential Number | 8 digits | Numeric sequential ID issued by National Police Directorate (DGP) | 12345678 |
| 9 | Control Letter | 1 letter | Uppercase letter computed via Modulo 23 with TRWAGMYFPDXBNJZSQVHLCKE table | Z |
DNI Validation Algorithm (Modulo 23)
The Spanish Police and AEAT calculate the control letter via integer division by 23:
Letter = "TRWAGMYFPDXBNJZSQVHLCKE"[Number % 23]
- 1. Extract the 8 numeric digits of the DNI.
- 2. Compute integer remainder: Remainder = Number % 23.
- 3. Index the official conversion string: TRWAGMYFPDXBNJZSQVHLCKE.
- 4. Confirm match with the 9th character.