Spanish DNI, NIE and NIF Validator
Check the control letter of a Spanish DNI or NIE, or work it out from the number. Tax numbers of companies are recognised by their first letter.
Enter the 8 digits of a DNI, or X, Y or Z and the 7 digits of an NIE, to get the letter; enter the whole number to check it. Spaces, dots and hyphens are ignored.
Enter a number to see the result.
The result says only whether the format and the control letter are correct. It does not tell you whether the number has been issued or who it belongs to.
Test numbers
Test values only. Do not use them as the number of a real person or organisation.
Random numbers with a correct control letter, for development and testing. A random number can match one that has really been issued.
How the control letter is calculated
| Remainder | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Letter | T | R | W | A | G | M | Y | F | P | D | X | B |
| Remainder | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | |
| Letter | N | J | Z | S | Q | V | H | L | C | K | E |
- DNI: divide the 8-digit number by 23 and look up the remainder in the table. 12345678 divided by 23 leaves 14, so the letter is Z: 12345678Z (the Ministerio del Interior's example).
- NIE: replace the first letter X with 0, Y with 1 or Z with 2, then calculate the same way with the 8 digits.
- The table has 23 letters: I, Ñ, O and U are never control letters.
- NIFs the tax agency assigns to people without a DNI or NIE start with K, L or M, and those of companies and other entities start with a letter for the legal form. The regulations give their structure but not how their last character is calculated, so the tool recognises them without checking it.
- Everything runs in your browser. The numbers you enter are not sent to LeedyBox or saved.
Source: Ministerio del Interior: Cálculo del dígito de control del NIF/NIE (Internet Archive, 2025-12-30) · Last checked:
Source: BOE: Real Decreto 255/2025, de 1 de abril, por el que se regula el Documento Nacional de Identidad · Last checked:
Source: BOE: Real Decreto 1065/2007 (Reglamento General de gestión e inspección tributaria), artículos 19 y 20 · Last checked:
Source: BOE: Orden EHA/451/2008 (texto consolidado, modificada por la Orden HAP/5/2016) · Last checked:
Wrong result? If a correct number is marked as wrong, email us the type of number and the result you expected. Please do not send a real person's DNI or NIE: a generated test number that shows the problem is enough.
Does a sentence on this page sound unnatural in your language? Let us know that too.
How to use
- Type a DNI or NIE in the box. With the digits only (8 for a DNI, X, Y or Z and 7 for an NIE) the tool shows the control letter; with the letter at the end it checks it.
- Read the verdict: a green tick means the letter matches the number, a red cross shows the letter it should be. A NIF starting with K, L, M or a company letter is recognised, and its last character is not checked.
- For tests, choose DNI or NIE and how many, then press Generate. Copy the list with Copy all.
Frequently asked questions
How is the DNI letter calculated?
Divide the 8-digit DNI number by 23 and take the remainder, from 0 to 22. Each remainder has a letter: 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 E. For 12345678 the remainder is 14, so the DNI is 12345678Z.
What is the difference between DNI, NIE and NIF?
The DNI is the identity card of Spanish citizens, and its number with the letter is also their tax number (NIF). The NIE is the identity number of foreign nationals, and it is their NIF too. The NIF is the tax number in general: people without a DNI or NIE receive one starting with K, L or M from the Agencia Tributaria, and companies have their own NIF.
How is the letter of an NIE calculated?
An NIE starts with X, Y or Z, followed by 7 digits and a letter. Replace X with 0, Y with 1 or Z with 2 to get an 8-digit number, then use the same table as for the DNI. For example, X1234567 becomes 01234567, which leaves 19 when divided by 23, so the NIE is X1234567L.
Does a correct letter mean the number exists?
No. The letter only protects against typing mistakes, and any 8-digit number has a correct letter. The tool cannot tell whether a number has been issued or who holds it; only the issuing authority can.
Why is the last character of a company NIF not checked?
Orden EHA/451/2008 says that a company NIF is a letter for the legal form, seven digits and a control character, but it does not give the calculation. LeedyBox only checks rules published by an official source, so it shows the legal form and leaves the control character unchecked.