Spanish DNI/NIE Calculator

Calculate the check letter for a Spanish DNI or NIE, or paste a full document to confirm its letter is correct. Switch between the two modes with the buttons below.

Processed entirely in your browser. This validator runs on your device using JavaScript. The number you enter is never sent to a server, stored, or logged, and nothing leaves your device.

8 digits for a DNI, or X, Y, or Z followed by 7 digits for a NIE.

How It Works

The final letter on a Spanish DNI or NIE is not chosen freely. It is calculated from the digits, which is why a small typo in the number almost always produces the wrong letter and gives the mistake away.

The method is a modulo 23 operation, which is just a fancy way of saying "the remainder left after dividing by 23". Step by step, it works like this:

  1. Start with the number. For a DNI, that is simply the eight digits as they are.
  2. If it is a NIE, first swap the leading letter for a digit: X becomes 0, Y becomes 1, and Z becomes 2. So Y1234567 turns into 11234567. Either way, you now have an eight-digit number to work with.
  3. Divide that number by 23 and throw away the whole part, keeping only the remainder, which is a value from 0 to 22.
  4. Line the remainder up against the fixed list of 23 letters, counting from zero: T, R, W, A, G, M, Y, F, P, D, X, B, N, J, Z, S, Q, V, H, L, C, K, E.
  5. The letter sitting at that position is the check letter.

There are exactly 23 letters because the list deliberately leaves out I, O, U, and the letter N with a tilde, so that a letter is never mistaken for a digit or for another letter. That is also why the divisor is 23 rather than some rounder number.

Worked Example

Take the sample number 12345678, which is an example and not a real document. Dividing 12345678 by 23 gives 536768 with 14 left over, so the remainder is 14. Counting from zero, position 14 in the list above is the letter Z, so the full DNI would be 12345678Z. For a NIE such as X1234567, the X first becomes 0, giving 01234567, which divided by 23 leaves a remainder of 19, and position 19 is the letter L, giving X1234567L.

When You Would Use This

This is handy when you have to write a DNI or NIE onto a form and want to be sure it is right, or when a document is worn and you cannot read the last character clearly. Someone renting a flat, opening an account, signing a contract, or filling in an official application can confirm in seconds that the number and its letter agree, and avoid a form that gets bounced back for a single wrong character.

Frequently Asked Questions

What is the difference between a DNI and a NIE?

A DNI is the national ID number for Spanish citizens: eight digits and a letter. A NIE is the identity number for foreigners in Spain: a leading letter X, Y, or Z, then seven digits, then a check letter. Both use the same method to work out that final letter.

How is the check letter chosen?

The number is divided by 23, and the remainder points to one letter in a fixed list of 23. There are 23 letters because the alphabet used here leaves out I, O, U, and N with a tilde to avoid mixing them up with digits or with each other.

Why does a NIE letter get replaced with a number first?

A NIE starts with a letter, but the calculation needs digits. So X becomes 0, Y becomes 1, and Z becomes 2. After that swap the NIE is treated as an eight-digit number and follows exactly the same steps as a DNI.

Does a correct letter mean the DNI is real?

No. The letter only proves the number and letter are consistent with each other. It does not mean the document was ever issued or that it belongs to a particular person. It is a format check, not a lookup.

Can I use this if I forgot the letter on my own document?

Yes. Switch to the calculate mode, type the eight digits of your DNI or the letter and seven digits of your NIE, and the tool returns the letter that belongs with it.