No signupFree tool

Validate any NIF · NIE · CIF in 1 second

Paste a Spanish tax ID and the validator tells you if it's correct, what type it is, and what each part means. If the control letter is wrong, we tell you what it should be. 100% in your browser — no server, no storage, no tracking.

Useful before issuing an invoice · No card · No email

Try with:

Official algorithm · DNI: mod 23 → "TRWAGMYFPDXBNJZSQVHLCKE" · CIF: Orden EHA/451/2008

The algorithm

How the control letter is calculated

So you can trust the result: the calculation is 100% defined by public regulation. Any validator (official or not) uses exactly this algorithm.

DNI / NIF for natural persons

8 digits + letter

  1. 1. Take the 8 digits of the DNI.
  2. 2. Calculate numero mod 23.
  3. 3. Look up the index in the table TRWAGMYFPDXBNJZSQVHLCKE.

Example: 51276680 mod 23 = 20 → position 20 → letter C

NIE

X/Y/Z + 7 digits + letter

  1. 1. Replace X→0, Y→1, Z→2.
  2. 2. Apply the DNI algorithm to the result.
  3. 3. The X/Y/Z prefix indicates the origin (X residents pre-2008, Y from 2008, Z reserved).

Example: Y1234567 → 11234567 mod 23 = 10 → letter X

CIF / NIF for entities

Letter + 8 characters

  1. 1. Letter: entity type (A=SA, B=SL...).
  2. 2. 2 digits: province.
  3. 3. 5 digits: AEAT sequential number.
  4. 4. Control: weighted sum of positions per Orden EHA/451/2008.

A more complex algorithm — check the source code for detail.

Inside Cofactu

The same thing, but automatic — when you create a customer

You don't have to remember to paste the NIF here. Cofactu validates it every time you create a customer or issue an invoice, and blocks the submission to AEAT if the ID doesn't add up — the 4001 rejection never happens.

If the NIF doesn't add up, the button is blocked and we tell you which character is wrong — before the invoice goes out.

Use cases

Why validate a NIF before invoicing?

Avoid AEAT rejections

If you issue a VeriFactu invoice with a badly formed NIF, AEAT rejects it with error 4001 and you have to correct it. Pre-validating avoids that cycle. Penalties for recurring errors can reach 50,000 €/year.

Validate when creating a customer

In Cofactu, the customer creation form automatically validates the NIF before saving. If you check it here first, you make sure the downstream chain (invoice → Modelo 303 → filing with AEAT) doesn't fail at the easiest end.

Verify B2B contracts

Before signing a contract with a company, validating the CIF at least confirms the format is correct. It doesn't verify the company is active — for that you need to check the AEAT tax office with the customer's certificate.

Intra-community operations

For Modelo 349 (intra-community operations) you need the foreign customer's VAT number — the equivalent of a CIF in their country. This validator doesn't cover foreign VAT numbers, only Spanish CIF, but it's the first step.

FAQ

Frequently asked questions

How is the NIF (DNI) check letter calculated?
Take the 8 digits of the DNI, calculate modulo 23 (number mod 23), and look up the result in the official table "TRWAGMYFPDXBNJZSQVHLCKE". For example, for 51276680 → 51276680 mod 23 = 20 → letter "C".
What's the difference between NIF, DNI, NIE and CIF?
DNI is the physical ID document for Spanish natural persons. NIF is the tax ID — for Spanish natural persons it matches the DNI; for resident foreigners it's the NIE (X/Y/Z + 7 digits + letter); for legal entities it's the CIF (entity type letter + 8 characters). Since 2008, AEAT uses NIF as the umbrella term for all of them.
What are the valid CIF letters by entity type?
A = Public limited company (Sociedad Anónima) · B = Private limited company (Sociedad Limitada) · C = General partnership · D = Limited partnership · E = Community of property owners (assets) · F = Cooperative · G = Association · H = Community of property owners · J = Civil partnership (Sociedad Civil) · N = Foreign entity · P = Local corporation · Q = Public body · R = Religious congregation · S = State administration · U = Temporary joint venture (UTE) · V = Other · W = Permanent establishment of a foreign entity. K, L, M are provisional.
Does the validator send my NIF to any server?
No. The calculation runs 100% in your browser with JavaScript. Cofactu doesn't store, log, or send to any server the data you paste in. You can review the algorithm's source code in src/lib/validators/spanish-id.ts in the public repository.
Why can a CIF's control character be a digit or a letter?
It depends on the entity type. Letters K, P, Q, R, S, N, W always require a letter. A, B, E, H always require a numeric digit. C, D, F, G, J, U, V accept both formats. This is set by Orden EHA/451/2008, which regulates the CIF format.
What is this validator for?
To validate, before issuing an electronic invoice, that your customer's NIF/CIF is correctly formed. If your customer's NIF is invalid, AEAT will reject the invoice with error 4001 when it's submitted via VeriFactu — and you'll have to correct it. Pre-validating avoids that cycle.
Does it work offline?
Yes. Once the page has loaded, the validator works without a connection. It's useful for quick on-site checks without internet access.

Cofactu validates NIFs automatically when you create a customer

If you issue more than 2 invoices/month, stop pre-validating by hand. Cofactu does it every time you create a customer or issue an invoice, and blocks the submission to AEAT if something doesn't add up.

Ready to invoice without the headaches?

Start free or browse the plans. Your first VeriFactu invoice in under 10 minutes.

No card requiredCancel in 1 clickExport anytime