Calculate DNI letter

Online calculator for Spanish ID letter. Discover which letter corresponds to your ID number.

Numbers only, 8 digits

Your DNI letter

Enter your ID number

How is the DNI letter calculated?

The DNI letter is calculated using a simple mathematical algorithm: the ID number is divided by 23 and the remainder of that division indicates the position of the letter in a predefined table of 23 letters.

Official formula:

letra = "TRWAGMYFPDXBNJZSQVHLCKE"[numeroDNI % 23]

Calculation example:

For ID 12345678:
12345678 % 23 = 14
Letter at position 14 = Z
Complete ID: 12345678-Z

ID letter table

Remainder 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

What is the DNI letter?

The DNI letter is an alphabetic character assigned to each Spanish National Identity Document. It serves as a control digit to verify that the ID number is correct and avoid transcription errors.

How does the algorithm work?

The algorithm divides the ID number (8 digits) by 23. The remainder of that division (a number from 0 to 22) is used as an index in the letter string TRWAGMYFPDXBNJZSQVHLCKE. This string is officially defined by the Ministry of Interior.

  • Official algorithm: uses Ministry of Interior formula
  • Instant: calculates the letter in milliseconds
  • 100% accurate: guaranteed exact result
  • Complete table: visualize all 23 possible letters
  • Free: online calculator available 24/7
  • No registration: we don't save or store your ID

Frequently Asked Questions

How is the DNI letter calculated?
The DNI letter is calculated by dividing the ID number by 23. The remainder of that division (a number from 0 to 22) indicates the position of the letter in the official string: TRWAGMYFPDXBNJZSQVHLCKE.
Why divide by 23?
It is divided by 23 because there are exactly 23 possible letters in the Spanish DNI. The Ministry of Interior established this algorithm to generate a unique control letter for each ID number.
What letters can a DNI have?
A Spanish DNI can have one of these 23 letters: T, R, W, A, G, M, Y, F, P, D, X, B, N, J, Z, S, Q, V, H, L, C, K, E. They are in this specific order and each corresponds to a remainder of the division by 23.
What is the purpose of the DNI letter?
The DNI letter serves as a control digit to verify that the ID number is correct. It helps detect transcription errors and prevents invalid ID numbers from being accepted in official procedures.
What is the official formula?
The official formula is: letter = "TRWAGMYFPDXBNJZSQVHLCKE"[DNInumber % 23]. The % symbol represents the remainder of the division, also known as modulo.
Do all DNIs have a letter?
Yes, all current Spanish DNIs have a letter. Old DNIs did not have a letter, but for decades all have included this alphabetic control digit.
Does this calculator save my DNI?
No. This calculator works completely in your browser. We do not save, store or send your ID number to any server. The calculation is performed locally on your device.
What if my DNI has less than 8 digits?
Spanish DNIs always have 8 digits. If your ID has fewer digits (for example, 1234567), you must add zeros to the left to complete 8 digits (01234567).