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
Official algorithm · DNI: mod 23 → "TRWAGMYFPDXBNJZSQVHLCKE" · CIF: Orden EHA/451/2008
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. Take the 8 digits of the DNI.
- 2. Calculate
numero mod 23. - 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. Replace X→0, Y→1, Z→2.
- 2. Apply the DNI algorithm to the result.
- 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. Letter: entity type (A=SA, B=SL...).
- 2. 2 digits: province.
- 3. 5 digits: AEAT sequential number.
- 4. Control: weighted sum of positions per Orden EHA/451/2008.
A more complex algorithm — check the source code for detail.
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.
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.
Frequently asked questions
How is the NIF (DNI) check letter calculated?
What's the difference between NIF, DNI, NIE and CIF?
What are the valid CIF letters by entity type?
Does the validator send my NIF to any server?
Why can a CIF's control character be a digit or a letter?
What is this validator for?
Does it work offline?
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.