The DNI/NIE Generator creates Spanish identity numbers — Documento Nacional de Identidad (for residents) or Número de Identidad de Extranjero (for foreign nationals) — with the final control letter computed correctly.
What it is
A DNI has 8 digits followed by a letter; a NIE starts with X, Y, or Z, followed by 7 digits and another letter. In both cases the final letter isn't random: it comes from the remainder of dividing the number by 23, applied to the fixed string TRWAGMYFPDXBNJZSQVHLCKE (23 letters, chosen to avoid visual confusion with vowels and similar-looking characters). For a NIE, the initial letter (X, Y, or Z) is converted to 0, 1, or 2 before the calculation.
This tool generates documents that pass that check, but they're fictitious — they don't belong to anyone and aren't looked up against any Dirección General de la Policía database. Useful for:
- Testing registration forms that accept DNI and NIE.
- Bulk generation, with .txt download.
- Validating an existing document on the same page.
How to use it
Pick a quantity and click Generate DNI/NIE — the tool randomly picks between the two formats. Copy or download the result. To check an existing document, use the Validator tab.
How the control letter is calculated
For a DNI, divide the 8-digit number by 23 and use the remainder as an index into the 23-letter table. For a NIE, the initial letter is worth 0 (X), 1 (Y), or 2 (Z); that value is multiplied by 10 million and added to the remaining 7 digits before applying the same division by 23. It's a much simpler algorithm than Mexico's RFC or Brazil's CPF — just a table and a division.
Worked example
For DNI 12345678, divide the number by 23: the remainder points to an index in the TRWAGMYFPDXBNJZSQVHLCKE table, and the matching letter is the correct control letter. For a NIE starting with X, add 0 to the remaining 7 digits before the same division (Y adds 10 million, Z adds 20 million). The result is always one of the 23 possible letters.