ForHosting KIT · Developer Utilities

Spanish DNI/NIF letter calculator

Type the eight digits of a Spanish DNI and get its control letter: 12345678 leaves a remainder of 14 when divided by 23, so the letter is Z and the full number is 12345678Z. Paste a full DNI, NIF or NIE to check it. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Dni
12345678
You get
Input
12345678
Kind
dni
Number
12345678
Letter
Z

Spanish national identity numbers (DNI) and personal tax identifiers (NIF) share a single public check: eight digits followed by a control letter taken from a fixed twenty-three-character table. Residents, expats filling forms, payroll tools, and KYC flows constantly need either to discover the correct letter from the numeric body or to confirm that a typed full identifier matches the official rule. This Spanish DNI/NIF letter calculator accepts an eight-digit body—or a full nine-character DNI with letter—applies the Agencia Tributaria modulo-twenty-three mapping, and returns the control letter, the completed identifier, and a clear valid flag when a letter was supplied. NIE identifiers that begin with X, Y, or Z use the same table after the standard digit substitution. Spaces and hyphens are stripped so clipboard paste from documents still works.

How the Spanish DNI control letter is computed

Every Spanish DNI for a natural person is eight decimal digits plus one alphabetic control character. The digits form an integer N between zero and ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine; leading zeros are significant and kept in the displayed body so that a document printed as zero zero one two three four five six is still the number one hundred twenty-three thousand four hundred fifty-six for arithmetic. The control letter is not a free choice of the citizen: it is completely determined by N.

Compute the remainder of N divided by twenty-three, then look that remainder up in the official ordered table of twenty-three letters: T R W A G M Y F P D X B N J Z S Q V H L C K E. Remainder zero maps to T, one to R, fourteen to Z, and so on through twenty-two to E. The letters I, Ñ, O, and U never appear in this table, which is a deliberate design to avoid visual confusion with digits and with Spanish orthography.

The same modular rule is the personal NIF check used on tax forms: for residents the NIF is simply the DNI including its letter. Foreign-resident NIE numbers begin with X, Y, or Z followed by seven digits and a letter; before taking the modulo, X is replaced by zero, Y by one, and Z by two so the engine still works on an eight-digit integer.

Where checking the DNI letter saves trouble

Onboarding and KYC forms for Spanish customers often ask users to type a DNI or NIF and need an instant client-side check before a slower back-office review. Payroll and HR imports receive employee identifiers from spreadsheets where a single wrong letter would reject a whole batch; a deterministic oracle that returns expected letter and valid lets importers flag rows without calling government portals.

Educational sites that rank for phrases such as spanish dni letter calculator or dni nif control letter need a live free tool whose browser path matches automation so tutorial screenshots stay accurate. Expats and residents recovering a faded document may only remember the eight digits and need the letter to complete online appointments, tax filings, or mobile contracts.

Form and KYC pre-checks

Validate a typed Spanish DNI or NIF letter before submit so users fix typos without a server round-trip to government systems.

Recover the control letter from digits

Compute the official letter from an eight-digit body when a document is worn, partially legible, or stored without the letter.

Batch payroll and CRM imports

Score rows of Spanish identifiers in scripts: recompute the letter, set valid, and quarantine mismatches before they hit HR systems.

How is the Spanish DNI control letter calculated?

Take the eight-digit body as an integer, compute that number modulo twenty-three, and pick the letter at that index in the official table TRWAGMYFPDXBNJZSQVHLCKE. For example, 12345678 modulo 23 is 14, which maps to Z.

What is the difference between DNI and NIF here?

For natural persons the personal NIF is the DNI including its control letter. This tool computes and checks that shared letter. Company CIF numbers use a different scheme and are outside this calculator.

Does it support NIE numbers?

Yes. NIE forms X, Y, or Z plus seven digits (optional letter) use the same table after mapping X to 0, Y to 1, and Z to 2.

What happens if the letter is wrong?

When you send a full identifier, the response still includes the expected letter and full string, and valid is false if the provided letter does not match.

Why do the letters I, Ñ, O and U never appear at the end of a DNI?

They are left out of the table of 23 control letters on purpose, to avoid confusion with digits and with Spanish spelling. A DNI that ends in one of them cannot be correct.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/enc/dni-spain

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/enc/dni-spain \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dni":"12345678"}'
{
  "dni": "12345678"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "enc.dni_spain",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Malformed input fails with invalid_input instead of inventing a letter.

Input contract, response shape, and validation modes

The value may be an eight-digit body only, in which case the capability runs in compute mode: it returns the control letter, the completed full identifier, the remainder used for the table index, kind set to dni, mode set to compute, and valid true because no conflicting letter was supplied. NIE bodies of the form letter X Y or Z plus seven digits, with or without a trailing control letter, follow the same two modes with kind nie. Spaces, dots, hyphens, underscores, and slashes are removed before parsing so numbers copied from PDFs or Spanish documents with separators still parse. On success the body also includes the fixed table string so clients can render the full mapping next to the answer without hard-coding a second copy. POST a JSON body with one required string field named dni. Aliases text, input, number, nif, value, and s are accepted so thin clients and generic text boxes can reuse the same endpoint without renaming fields. The value may also be eight digits plus a letter such as one two three four five six seven eight Z; that path is validate mode: the engine recomputes the expected letter, compares it to the provided letter after uppercasing, sets valid to true or false, and echoes provided_letter so UIs can highlight a mistyped character without guessing. Empty strings, non-string objects, wrong digit counts, letters outside the official table, and patterns that are neither DNI nor NIE raise invalid_input with a message that names the problem; those failures are not billed. Successful API calls cost the published base price of $0.002 per item; the in-browser tool remains free for interactive checks.

Where a DNI letter API earns its keep

Developers building multi-country tax-id suites can call this specialised endpoint when the country is Spain and they want the letter itself, not only a boolean, while keeping a separate multi-country format checker for other jurisdictions.

What does the Spanish DNI/NIF letter calculator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →