Validate a Spanish NIF
VerifNow validates every kind of Spanish tax identification number (número de identificación
fiscal): a Spanish national’s DNI, a foreign national’s NIE, the K, L and M series, and the NIF of a
company or other entity. nifDetails says which one it received, whether it belongs to a person, and
for an entity its legal form.
Basic NIF validation
POST https://api.verifnow.io/api/v1/validate/nif
X-API-KEY: your_api_key_here
Content-Type: application/json
{
"value": "B-12345674"
}Example response
{
"valid": true,
"message": "Valid NIF",
"normalizedValue": "B12345674",
"originalValue": "B-12345674",
"validationLevel": "STANDARD",
"nifDetails": {
"type": "ENTITY",
"natural_person": false,
"checksum_valid": true,
"entity_letter": "B",
"entity_type": "Private limited company (Sociedad de responsabilidad limitada)"
}
}Spaces, dots and dashes are accepted, and so is a leading ES: a Spanish VAT number is ES followed
by the NIF, so a value copied from an invoice works as typed.
The kinds of NIF
type | Shape | Who | Control character |
|---|---|---|---|
DNI | 8 digits + letter — 12345678Z | Spanish national | Number modulo 23 in TRWAGMYFPDXBNJZSQVHLCKE |
NIE | X, Y or Z + 7 digits + letter — X1234567L | Foreign national | X→0, Y→1, Z→2, then as for a DNI |
NIF_K | K + 7 digits + letter | Spanish national under 14 without a DNI | As for a DNI, on the 7 digits |
NIF_L | L + 7 digits + letter | Spanish national resident abroad, in Spain under six months | As for a DNI, on the 7 digits |
NIF_M | M + 7 digits + letter | Foreign national without a NIE | As for a DNI, on the 7 digits |
ENTITY | Letter + 7 digits + digit or letter — B12345674 | Company or other entity | Computed from the 7 digits — see below |
Entities and their legal form
For an entity, the first letter is its legal form, as set by Orden EHA/451/2008:
| Letter | Legal form |
|---|---|
A | Public limited company (sociedad anónima) |
B | Private limited company (sociedad de responsabilidad limitada) |
C | General partnership |
D | Limited partnership |
E | Joint ownership, estate, or other entity without legal personality |
F | Cooperative |
G | Association |
H | Community of property owners |
J | Civil partnership |
N | Foreign entity |
P | Local authority |
Q | Public body |
R | Religious congregation or institution |
S | State administration body |
U | Temporary business association (UTE) |
V | Other entity type |
W | Permanent establishment of a non-resident entity |
The control character is a digit, or the letter at that position in JABCDEFGHI. The Orden does not
say which form each letter uses, and published sources disagree for several of them. VerifNow enforces
only what they all agree on — a digit for A, B, E and H, a letter for P, Q and S — and accepts either
form for every other letter. Rejecting a real company over a disputed rule would be worse than
accepting a rare form.
Common responses
| Input | valid | message |
|---|---|---|
12345678Z | true | Valid NIF |
X1234567L | true | Valid NIE |
B12345674 | true | Valid NIF |
12345678A | false | NIF control letter does not match — please check the number |
B12345675 | false | NIF control character does not match — please check the number |
A1234567D | false | A NIF starting with A ends with a digit |
1234 | false | Not a Spanish NIF: expected 8 digits and a letter, a NIE such as X1234567L, or a company NIF such as B12345674 |
A valid NIF is not a valid VAT number
A company’s EU VAT number is ES followed by its NIF — but only once it is registered for
intra-community operations. Validate the VAT number with /validate/vat when
you need to apply the reverse charge: the NIF check says the number is well formed, VIES says whether it
is registered. The article explains why the two can disagree.
Testing
Use the conventional samples 12345678Z (DNI) and X1234567L (NIE). Do not invent other personal
NIFs: roughly one in twenty-three random numbers has the right letter, and an invented valid one may be
a real person’s. Company NIFs identify businesses and are public, so they are safe in fixtures.
What VerifNow keeps
The usage log that meters your calls stores a NIF as *** — no digits at all.
Next steps
- Validating a Spanish NIF — persons, foreigners and companies, and why a NIF is not a VAT number
- Validate VAT