Skip to content

DNI Letter Calculator (Spain)

Find the check letter of a Spanish DNI or NIE, or validate a full DNI/NIE number.

Your details

What do you want to do?

DNI: 8 digits, e.g. 12345678. NIE: X, Y or Z + 7 digits, e.g. X1234567.

Results update as you type

Check letter

Z

Full number
12345678Z
Remainder of the division by 23
14

Computed in your browser: the number is not sent to our server or stored by this site.

Step-by-step solution
  1. 12345678 ÷ 23 = 536768, remainder 14
  2. Position 14 in TRWAGMYFPDXBNJZSQVHLCKE (counting from 0) → Z

Rules valid for 2026 · Ministerio del Interior — DNI

Every Spanish identity number ends in a check letter. On the DNI (Documento Nacional de Identidad) the eight digits are followed by one letter, and the same letter turns the DNI into the person's tax number (NIF). Foreign residents receive an NIE (Número de Identidad de Extranjero), which starts with X, Y or Z, has seven digits and also ends with a check letter.

The letter is not chosen at random: it is calculated from the digits, so a typo in a form can be caught before the number reaches a bank, an employer or the tax agency. This calculator applies the rule published by Spain's Ministry of the Interior. Type the digits to find the letter, or type a complete number to validate it. You also see the remainder and every step of the calculation.

Privacy. The calculation runs in your browser. The number is not sent to our server, is not stored, and is never added to the page address, so a shared link never contains it. A correct letter only means the number is well formed: it does not prove that the document exists, belongs to anyone or is still valid.

How to use this calculator

  1. Choose Find the letter if you only know the digits, or Validate a DNI/NIE if you want to check a complete number.
  2. Type the number. Spaces, dots and hyphens are ignored, so 12.345.678 and 12345678 give the same result. A DNI with fewer than eight digits is padded with zeros on the left, as on the card.
  3. For an NIE, keep the initial X, Y or Z: the calculator replaces it with 0, 1 or 2 before dividing.
  4. Read the letter (or the verdict), the full number and the remainder. The steps show the division so you can redo it on paper.

The formula

Take the eight-digit number NN and divide it by 23. The remainder rr is a whole number from 0 to 22, and it points to a position in a fixed string of 23 letters:

r=N mod 23letter=TRWAGMYFPDXBNJZSQVHLCKE[r]r = N \bmod 23 \qquad \text{letter} = \texttt{TRWAGMYFPDXBNJZSQVHLCKE}[r]
r 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
r 12 13 14 15 16 17 18 19 20 21 22
letter N J Z S Q V H L C K E

For an NIE, first replace the initial letter: X → 0, Y → 1, Z → 2, then apply the same rule to the resulting eight-digit number. The letters I, Ñ, O and U never appear, because they are too easy to confuse with digits or with other letters.

Worked example

DNI 12345678. 12 345 678÷23=536 76812\,345\,678 \div 23 = 536\,768 with remainder 12 345 678−23×536 768=1412\,345\,678 - 23 \times 536\,768 = 14. Position 14 in the table is Z, so the full number is 12345678Z.

NIE X1234567. Replace X with 0 → 01234567, that is 1 234 5671\,234\,567. 1 234 567÷23=53 6761\,234\,567 \div 23 = 53\,676 remainder 19, and position 19 is L: the full NIE is X1234567L.

Validating 12345678A. The digits give remainder 14, so the letter should be Z, not A: the calculator answers "Not valid" and shows Z as the correct letter.

Why a modulo-23 check catches typos

Dividing by a prime number such as 23 makes the letter sensitive to the most common mistakes. If you change a single digit, the number changes by between 1 and 9 times a power of ten, and none of those amounts is a multiple of 23, so the letter always changes. Swapping two adjacent different digits is also always detected. That is why forms and online services can reject a mistyped DNI instantly, without contacting any database. The check cannot catch every error, though: two numbers that differ by a multiple of 23 share the same letter.

Frequently asked questions

How do I calculate the letter of a DNI?

Divide the eight-digit number by 23 and keep the whole-number remainder (0 to 22). Look that position up in TRWAGMYFPDXBNJZSQVHLCKE, counting from 0: remainder 0 gives T, 1 gives R, 14 gives Z, 22 gives E.

How is the NIE letter calculated?

Replace the first letter by a digit (X = 0, Y = 1, Z = 2), which gives an eight-digit number, then apply the same modulo-23 rule as for a DNI. X1234567 becomes 01234567 and gets the letter L.

Does a valid letter mean the DNI is real?

No. The letter only shows that the number is internally consistent. Anyone can build a correct-looking number with this rule, so it says nothing about whether a document was issued, who holds it or whether it has expired.

Is the number I type stored anywhere?

No. The calculation is done in your browser and the number is not sent to our server or saved by this site. It does appear in the page address so results can be shared, so remove it before copying the link.

What about NIFs that start with K, L or M?

Those tax numbers are issued by the Spanish tax agency to minors without a DNI, non-resident Spaniards and some foreigners without an NIE. They follow their own rules and are not covered here; this calculator handles DNI and NIE numbers only.

Sources

Last updated:

More Other calculators

People also use