Skip to Content
GuidesValidate NIF (Spain)

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

typeShapeWhoControl character
DNI8 digits + letter — 12345678ZSpanish nationalNumber modulo 23 in TRWAGMYFPDXBNJZSQVHLCKE
NIEX, Y or Z + 7 digits + letter — X1234567LForeign nationalX→0, Y→1, Z→2, then as for a DNI
NIF_KK + 7 digits + letterSpanish national under 14 without a DNIAs for a DNI, on the 7 digits
NIF_LL + 7 digits + letterSpanish national resident abroad, in Spain under six monthsAs for a DNI, on the 7 digits
NIF_MM + 7 digits + letterForeign national without a NIEAs for a DNI, on the 7 digits
ENTITYLetter + 7 digits + digit or letter — B12345674Company or other entityComputed from the 7 digits — see below

For an entity, the first letter is its legal form, as set by Orden EHA/451/2008:

LetterLegal form
APublic limited company (sociedad anónima)
BPrivate limited company (sociedad de responsabilidad limitada)
CGeneral partnership
DLimited partnership
EJoint ownership, estate, or other entity without legal personality
FCooperative
GAssociation
HCommunity of property owners
JCivil partnership
NForeign entity
PLocal authority
QPublic body
RReligious congregation or institution
SState administration body
UTemporary business association (UTE)
VOther entity type
WPermanent 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

Inputvalidmessage
12345678ZtrueValid NIF
X1234567LtrueValid NIE
B12345674trueValid NIF
12345678AfalseNIF control letter does not match — please check the number
B12345675falseNIF control character does not match — please check the number
A1234567DfalseA NIF starting with A ends with a digit
1234falseNot 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

Last updated on