dni letter calculator

DNI Letter Calculator

Enter the DNI number (digits only). Optionally add a letter to validate whether your full DNI is correct.

Official sequence used: TRWAGMYFPDXBNJZSQVHLCKE

What is the DNI letter?

The Spanish DNI (Documento Nacional de Identidad) includes a control letter after the numeric part of the ID. This letter is not random. It is calculated from the number using an official algorithm designed to reduce typing mistakes and invalid records.

In practice, this means if you know the 8-digit DNI number, you can always compute the corresponding letter. If the letter does not match, the DNI is invalid or mistyped.

How the DNI letter is calculated

Step-by-step formula

  • Take the DNI number (for example, 12345678).
  • Calculate the remainder when dividing by 23: 12345678 % 23.
  • Use that remainder as an index in this string: TRWAGMYFPDXBNJZSQVHLCKE.
  • The character at that position is the DNI letter.

So in compact form: letter = letters[number % 23].

Why this works

The modulo-23 method creates a predictable control mechanism. Since the same number always maps to the same letter, agencies and systems can quickly detect common errors such as wrong digits or swapped characters.

How to use this DNI letter calculator

  • Enter up to 8 digits in the DNI number field.
  • Click Calculate Letter to get the official letter.
  • If you want to verify an existing DNI, also enter its letter first.
  • The tool will report whether the provided letter is valid for that number.

This calculator is useful for forms, onboarding workflows, HR administration, and any process where identity data quality matters.

Examples

Example 1: Calculate only

If the number is 12345678, the result is letter Z, so the full DNI is 12345678Z.

Example 2: Validate a full DNI

If someone enters number 12345678 with letter A, validation will fail because the expected letter is Z.

Common mistakes to avoid

  • Using lowercase/uppercase inconsistently (the validation is case-insensitive, but storage should usually be uppercase).
  • Typing extra spaces before or after the number.
  • Confusing DNI with NIE calculation rules (NIE uses a slightly different first-step transformation).
  • Dropping leading zeros in systems that require a fixed 8-digit format.

FAQ

Does this include NIE calculation?

This page focuses on DNI numbers. NIE numbers can be calculated with a related approach, but they require converting the initial letter (X/Y/Z) before applying the same modulo process.

Is the method official?

Yes. The letter mapping and modulo-23 rule are the standard method used across Spain for DNI control letters.

Can I use this tool in production?

You can use this logic as a front-end helper, but production systems should also validate server-side to prevent tampering and ensure consistent data integrity.

🔗 Related Calculators