Skip to content

Calculate the DNI, NIF and NIE letter

To calculate the DNI letter, divide the number by 23 and match the remainder in the official table. Calculate or check DNI, NIF, NIE and CIF control characters instantly, free and without saving any data.

DNI and NIE letter calculator

Without a letter to calculate; with a letter to check.

Examples:

Supports DNI, NIE (X, Y, Z), special NIF (K, L, M) and company/entity NIF (CIF).

The calculation runs in your browser. We do not send or store the number you enter. If you copy the share link, the number is included in its URL fragment (#numero=…).

Example12345678 → remainder 14 → Z
  1. Entered number
    12345678
    12345678
  2. Divide by 23
    12345678 ÷ 23
    mod 23 · quotient: 536768
  3. Remainder (÷ 23)
    14
    12345678 mod 23 = 14
  4. Corresponding letter
    Z
    12345678Z

How the DNI letter is calculated

The DNI letter is calculated by dividing the 8-digit number by 23 and taking the remainder of the division, which is always between 0 and 22.Each remainder corresponds to a fixed letter in the official table: remainder 0 is T, remainder 1 is R and remainder 14 is Z. This method is called the modulo-23 algorithm, and the Spanish Ministry of the Interior describes it on its official page about the NIF/NIE control character calculation.

  1. Take the 8 digits of the DNI number

    Include leading zeros: 1234567 is written as 01234567.

  2. Divide the number by 23

    Keep the remainder of the division, not the quotient.

  3. Look up the remainder in the table

    The letter at that position in the DNI letter table is the DNI letter.

The Spanish National Identity Document (DNI) is regulated by Royal Decree 255/2025 of 1 April, which replaces the former Royal Decree 1553/2005, and Organic Law 4/2015 makes holding a DNI compulsory from the age of 14. The DNI letter calculation is public and does not depend on date of birth, sex or province.

DNI letter, personal NIF and control character: how they relate

The DNI letter, the NIF letter and the DNI control character are the same piece of data.The Tax Identification Number (NIF) of a Spanish national is their DNI number followed by the letter, for example 12345678Z. The Spanish Tax Agency (AEAT), known as Hacienda, uses that NIF to identify every tax return. The letter detects typing errors, because changing a single digit of the number produces a different remainder and a different letter.

The Foreigner Identity Number (NIE) and special personal NIFs (K, L, M) use the same modulo 23. The NIF of companies and entities, known as CIF (Código de Identificación Fiscal), uses a modulo-10 algorithm with a control digit or letter: validate CIF · validate special NIF.

Worked example: from 12345678 to 12345678Z

DNI 12345678 takes the letter Z.You can repeat this calculation with any number in the diagram below the calculator.

  • 1. Integer division: 12 345 678 ÷ 23 = 536 768
  • 2. Quotient multiplied by 23: 536 768 × 23 = 12 345 664
  • 3. Remainder: 12 345 678 − 12 345 664 = 14
  • 4. Letter: 14 → Z(12345678Z)

How to calculate the DNI letter in Excel

With the 8-digit number in cell A1, use the formula that matches your Excel language:

  • =MID("TRWAGMYFPDXBNJZSQVHLCKE",MOD(A1,23)+1,1)Excel in English
  • =EXTRAE("TRWAGMYFPDXBNJZSQVHLCKE";RESIDUO(A1;23)+1;1)Excel in Spanish

MOD or RESIDUO returns the remainder of dividing by 23, and MID or EXTRAE takes the letter at that position; the +1 compensates for Excel counting from 1. With 12345678 in A1, both formulas return Z. For an NIE, first replace the initial X, Y or Z with 0, 1 or 2.

DNI letter table

The DNI and NIE letter table has 23 letters, one for each possible remainder from 0 to 22: T, R, W, A, G, M, Y, F, P, D, X, B, N, J, Z, S, Q, V, H, L, C, K and E. The Ministry of the Interior excludes the letters I, Ñ, O and U to avoid confusion with 1, N and 0.

DNI letter table
RemainderLetter
0T
1R
2W
3A
4G
5M
6Y
7F
DNI letter table
RemainderLetter
8P
9D
10X
11B
12N
13J
14Z
15S
DNI letter table
RemainderLetter
16Q
17V
18H
19L
20C
21K
22E

When you calculate a number with the calculator, the row for the resulting remainder is highlighted in this table.

How the NIE letter is calculated

The NIE letter is calculated by replacing the initial letter with a number (X = 0, Y = 1, Z = 2), dividing the result by 23 and looking up the remainder in the DNI letter table.The NIE is assigned by the Directorate General of the Police through the Foreigners' Office (Oficina de Extranjería) or National Police stations.

NIE X1234567 takes the letter L and its full number is X1234567-L:

  • 1. Prefix: X → 0, so X1234567 becomes 01234567.
  • 2. Remainder: 1 234 567 − (53 676 × 23) = 19
  • 3. Letter: 19 → L

The calculation is the same for the other 2 series: Y1234567 becomes 11234567, with remainder 10 and letter X (Y1234567X); Z1234567 becomes 21234567, with remainder 1 and letter R (Z1234567R).

The NIE appears on the residence permit, on the Foreigner Identity Card (TIE) and in arraigo (settlement) applications. To get just the letter use calculate NIE letter, and to check a complete NIE use check NIE.

Which procedures require the DNI or NIE with its letter

It is used, for example, in these 6 types of procedures:

  • Tax Agency (Hacienda)

    The Spanish Tax Agency (AEAT) asks for the NIF in the income tax return, when booking an appointment with Hacienda, when replying to a Hacienda request and when appealing a tax penalty.

  • Digital identification

    Registering for Cl@ve PIN and applying for the digital certificate from the Royal Mint (FNMT-RCM) require the DNI or NIE with its letter. The digital certificate for a legal entity is requested with the company's CIF and its representative's DNI.

  • Tax residence

    The certificate of tax residence in Spain is requested from the AEAT with the taxpayer's NIF.

  • Social Security

    The Social Security affiliation number, registering an employee and registering as self-employed are processed with the full DNI or NIE.

  • Immigration

    The Foreigners' Office identifies each residence permit, renewal or arraigo application with the NIE.

  • Notaries and Registrars

    Deeds of sale, loans and inheritances record the DNI or NIE of each party, and the notary checks the document before signing.

Spanish government online forms validate the letter before submitting the application and reject the data if the letter does not match the number. Check the letter with the DNI and NIE letter calculator before filling in any official form: a mistyped NIF means repeating the application.

Frequently asked questions

How do I find the DNI letter from the number?

To find the DNI letter from the number, divide the number by 23 and look up the remainder in the official DNI letter table. With the calculator on this page, just type the 8 digits and press “Calculate / check”: the letter appears instantly together with the step-by-step calculation.

What is the DNI letter for?

The DNI letter is used to detect errors when typing the DNI number. The letter works as a control character: if a digit is copied incorrectly, the remainder of the division by 23 changes and the letter no longer matches. The letter contains no personal data: no date of birth, sex or province.

Can I calculate the letter of a DNI that starts with zero?

Yes, the letter of a DNI that starts with zero is calculated the same way, keeping the leading zeros to complete 8 digits. DNI 1234567 is written 01234567, its remainder when divided by 23 is 19 and the corresponding letter is L (01234567L). The calculator keeps leading zeros.

What happens if the DNI letter is wrong?

A wrong DNI letter means the number or the letter has been typed incorrectly. The calculator shows “Incorrect letter”, the expected letter and the correct full number. The online portals of the Tax Agency and Social Security reject an NIF with the wrong letter.

Can I also check an NIF or CIF?

Yes, the calculator checks special NIFs (K, L, M) and company and entity CIFs. Special NIFs K, L and M use the modulo-23 algorithm on their 7 digits. The CIF uses a modulo-10 algorithm and ends in a digit or a letter depending on the legal form, as regulated by Orden EHA/451/2008.

Is the number I enter stored?

No, the number you enter is neither stored nor sent to any server. The DNI letter is calculated in your browser with JavaScript. The calculator does not store the number in cookies or browser storage. If you copy the share link, the number is included in its URL fragment (#numero=…).

How can I share the result?

To share the result, press “Copy link” below the result and send that link. The link includes the number at the end of the URL (#numero=…) and whoever opens it sees the same calculation. That fragment is processed in the browser and does not reach the server.