Spanish NIF / DNI letter calculator
Enter the digits of your Spanish DNI or NIE and get the check letter instantly. It also checks whether a complete document is valid. The calculation runs in your browser, with no data transmitted.
Accepts 8 digits (DNI) or a NIE starting with X, Y or Z. You can include the letter to check whether it is correct.
The DNI letter isn't random: here's how it's worked out
Many people assume the letter on a Spanish DNI is an administrative quirk, but it's a check character produced by a very specific operation. You take the full DNI number, divide it by 23 and look at the remainder (what's left over, a number from 0 to 22). That remainder points to a position in this official sequence of letters:
T R W A G M Y F P D X B N J Z S Q V H L C K EA remainder of 0 gives T, 1 gives R, and so on. Because the operation is fixed, a DNI number can have only one valid letter; that's why a wrongly written letter is spotted instantly. The letters I, Ñ, O and U were deliberately left out to avoid confusion with 1, 0 and other characters.
The NIE: one extra step before the calculation
The NIE, the document for foreign residents in Spain, starts with a letter (X, Y or Z) instead of being all numbers. To get its check letter, that initial letter is first replaced with a digit: X is 0, Y is 1 and Z is 2. The resulting number then goes through exactly the same division-by-23 calculation. This tool detects whether you've typed a DNI or a NIE and adjusts the sum for you.
Calculate or check, two uses in one
If you type just the numbers, it gives you the matching letter, handy when filling in a form and you can't remember yours. And if you type the number with a letter, it checks whether the letter is correct and warns you if it doesn't match, which is useful for anyone handling other people's data (a front desk, HR, a public office) who wants to confirm at a glance that a DNI is written correctly.