Skip to main content

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:

PositionFieldLengthMeaning & RuleExample
1 to 8Sequential Number8 digitsNumeric sequential ID issued by National Police Directorate (DGP)12345678
9Control Letter1 letterUppercase letter computed via Modulo 23 with TRWAGMYFPDXBNJZSQVHLCKE tableZ

DNI Validation Algorithm (Modulo 23)

The Spanish Police and AEAT calculate the control letter via integer division by 23:

Letter = "TRWAGMYFPDXBNJZSQVHLCKE"[Number % 23]
  1. 1. Extract the 8 numeric digits of the DNI.
  2. 2. Compute integer remainder: Remainder = Number % 23.
  3. 3. Index the official conversion string: TRWAGMYFPDXBNJZSQVHLCKE.
  4. 4. Confirm match with the 9th character.

Frequently Asked Questions (FAQ)