Pular para o conteúdo
Tool

DNI/NIE Generator (Spain)

Generate a Spanish DNI or NIE with the correct control letter under the official algorithm, or validate an existing document.

The generated documents are fictitious: the control letter is mathematically correct under the official (modulo-23) algorithm, but they don't belong to any real person and aren't checked against any official database. Use only for software testing.

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.

Frequently asked questions

What's the difference between DNI and NIE?

The DNI (Documento Nacional de Identidad) is for Spanish citizens and residents: 8 digits + letter. The NIE (Número de Identidad de Extranjero) is for foreign nationals: starts with X, Y, or Z, followed by 7 digits + letter. Both use the same control-letter algorithm.

Is the generated letter really valid?

It's mathematically valid: it follows the exact official modulo-23 algorithm. But the whole document is fictitious and doesn't exist in any real database.

Does this generate a CIF (Spanish company tax ID)?

No. The CIF uses its own algorithm, different from the individual DNI/NIE. This tool covers only individual documents.

About this content

Written by:
Ferramenta Grátis

Related tools