DNI Validator

Enter a Spanish DNI to check whether its control letter is correct.

Result

Valid
Z
12345678

How it is calculated

The tool checks only the control letter of a Spanish DNI, which has 8 digits followed by 1 letter. Spaces, dots and hyphens are removed and letters are made upper case first, so 12.345.678-z is read as 12345678Z. Then remainder = number mod 23 and the expected letter is the character at that position (counting from 0) in the string TRWAGMYFPDXBNJZSQVHLCKE. The result is Valid when the letter you typed equals the expected one, otherwise Invalid, and the expected letter is always shown. Input that is not exactly 8 digits plus a letter, including a foreigner NIE starting with X, Y or Z, gives no result. This is an arithmetic check only: it cannot tell whether the number was ever issued to a person.

Worked example

Enter 12345678Z. The number part is 12345678. Dividing by 23 gives 536768 with a remainder of 14 (23 × 536768 = 12345664, and 12345678 − 12345664 = 14). The character at position 14 of TRWAGMYFPDXBNJZSQVHLCKE is Z. That matches the Z you typed, so the tool reports Valid with number 12345678 and expected letter Z. Typing 12345678A instead would report Invalid, with the expected letter still shown as Z.

Try this example →

Common mistakes

  • Reading Valid as proof that the person exists. A correct letter only means the number and letter are consistent; many made-up numbers also pass.
  • Typing a NIE (the foreigner number starting with X, Y or Z) and expecting a verdict. This tool accepts 8 digits plus a letter only, and anything else gives no result rather than Invalid.
  • Leaving out leading zeros. A DNI with fewer than 8 digits, such as 1234567Z, is not accepted; write it with the zero in front (01234567).
  • Mixing up the letter and digit O or I. The control alphabet has no I, O, U or Ñ, so an expected letter never contains them.
  • Believing an Invalid result means fraud. Most often it is a typo in one digit or the letter, so re-check the document before drawing a conclusion.

About this calculator

Spain's national identity number, the DNI (Documento Nacional de Identidad), pairs an 8-digit number with a single control (check) letter that guards against typos and forged documents. The letter is derived deterministically: take the 8-digit number, compute its remainder on division by 23, and use that remainder (0–22) as an index into the fixed 23-character string "TRWAGMYFPDXBNJZSQVHLCKE" — the letter at that position is the correct one.

Because the algorithm is public and purely arithmetic, anyone can verify — but not forge new valid numbers from — a DNI's check letter without needing access to any government database, which is why banks, telecom providers and online services performing basic format validation in Spain check this letter locally before accepting an ID number. This tool checks DNI numbers only (8 digits followed by a letter); the foreigner-resident NIE, which starts with X, Y or Z, is not accepted.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    A handy use is catching typos in a form or spreadsheet. Change one digit or swap two neighbouring ones and the expected letter usually changes: 12345678 expects Z, while 12345687 expects T. Since there are only 23 possible letters, about one wrong number in 23 will still match its letter by chance, so a pass is a weak filter rather than an identity check. Where do you need to check DNIs, and which other national ID formats should we add?

Popular calculators

All Calculators