Small Business

Checking Spanish NIF, NIE and CIF Numbers: How the Letter Works

How Spanish tax ID numbers work: the DNI letter from mod 23, NIE with X, Y or Z, company NIF control characters, and how to validate them in batch.

Saizul Amin
Saizul Amin29 Oct 2026 · 3 min read
Checking Spanish NIF, NIE and CIF Numbers: How the Letter Works

Checking Spanish NIF, NIE and CIF Numbers: How the Letter Works

Spanish tax identification numbers appear on contracts, invoices, payroll and every official form. They are easy to mistype, and a wrong letter can block a payment, a tax return or a registration. Fortunately, every NIF includes a check that detects most errors. This guide explains how it works and how to use the NIF, NIE and CIF validator.

The NIF for Spanish citizens

For Spanish nationals, the NIF is the DNI number: 8 digits followed by a letter. The letter is not random: divide the number by 23, take the remainder and look it up in this sequence:

T R W A G M Y F P D X B N J Z S Q V H L C K E

A remainder of 0 gives T, 1 gives R, and so on. For example, 12345678 divided by 23 leaves a remainder of 14, which corresponds to Z, so the full NIF is 12345678Z.

The NIE for foreign nationals

Foreigners receive an NIE: a letter X, Y or Z, 7 digits and a control letter. To check it, replace X with 0, Y with 1 and Z with 2, and apply the same mod 23 rule to the resulting 8-digit number. X1234567L is valid: 01234567 mod 23 gives the letter L.

Special NIFs: K, L, M

Some individuals have special NIFs: K for Spaniards under 14 without DNI, L for Spaniards resident abroad without DNI, and M for foreigners who need a tax number but do not have an NIE. The same letter rule applies to the 7 digits.

Company NIF (formerly CIF)

Companies and other entities have an NIF that starts with a letter indicating the type:

  • A: public limited company (sociedad anónima)
  • B: limited company (sociedad limitada)
  • C: general partnership
  • E: community of goods
  • F: cooperative
  • G: association or foundation
  • H: community of owners
  • J: civil partnership
  • N: foreign entity
  • P: local authority
  • Q: public body
  • R: religious congregation
  • S: state administration body
  • U: joint venture
  • V: other types
  • W: permanent establishment of a non-resident

Then come 7 digits and a control character. The control is calculated by adding the digits in even positions, adding the digits of twice each odd-position digit, and taking 10 minus the last digit of the sum. Some types use a digit, others a letter (J, A, B, C, D, E, F, G, H, I for 0 to 9), others either.

What the check proves

A valid letter or digit shows the number is internally consistent, catching typing mistakes and swapped digits. It does not prove that the number belongs to a real person or an active company.

Using the validator

  1. Paste one or more numbers, one per line.
  2. Read the result: valid or not, and the type.
  3. For wrong numbers, see the expected letter or digit.
  4. Export the list.

A worked example

An HR department imports 200 employees from a spreadsheet. The validator flags 12345678A: the expected letter is Z, so the letter was mistyped. X1234567L is a valid NIE. B12345674 passes as a limited company NIF. The department corrects the flagged entries before running payroll.

Data protection

DNI and NIE numbers are personal data under the GDPR. Process them only for legitimate purposes, limit access and avoid sharing lists by email.

EU VAT numbers

For intra-EU operations, Spanish businesses use their NIF with the ES prefix as VAT number, after registering in the census of intra-community operators. Check them in the European VIES system before applying the reverse charge.

Limits

The validator checks formats and control characters. It does not confirm identity or company registration.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages