Generator · Spanish data
Spanish CIF
Endpoint GET /v1/es/cif
What it covers
Returns a valid Spanish CIF (tax id for legal entities) with a correct control character. Use `format=vat` for the `ES`-prefixed VAT number. Set `invalid=true` for a CIF with a deliberately wrong control character.
How it’s calculated
The Spanish CIF control character is a Luhn (mod-10) check digit computed over the 7-digit body, rendered as a digit for most entity types and mapped through the letter alphabet "JABCDEFGHI" for entity types P, Q, R, S, W, N.
Algorithm
- Start from a CIF body: one entity-type letter followed by exactly 7 digits (e.g. A + 5881850). The check character sits to the right of these 7 digits.
- Take only the 7 body digits as an array. The entity letter is NOT part of the checksum arithmetic — it only decides how the final result is rendered (see step 6).
- Compute a Luhn (mod-10) sum over the 7 digits, processing right-to-left. Toggle a 'doubling' flag that is TRUE for the rightmost digit and alternates thereafter. Because the body is 7 digits long, the doubled positions are the 1st, 3rd, 5th, 7th digits counted from the left (the odd 1-indexed positions).
- For each digit: if doubling is TRUE, multiply by 2 and, if the result exceeds 9, subtract 9 (equivalent to summing the two decimal digits). If doubling is FALSE, take the digit as-is. Add the resulting value to a running sum.
- Compute the control digit D = (10 - (sum mod 10)) mod 10. D is a single digit 0-9.
- Render the control character: if the entity letter is one of P, Q, R, S, W, N (letter-control types), output the letter at index D of the alphabet 'JABCDEFGHI' (J=0, A=1, B=2, ... I=9). For every other entity letter (A, B, C, D, E, F, G, H, J, N-excluded, U, V), output the digit D itself as a character.
- The full CIF is entityLetter + 7 digits + controlCharacter. The VAT form simply prefixes 'ES' to this (ES + CIF).
Worked example
CIF body A5881850? (entity letter A, digit-type control)
Body digits: 5 8 8 1 8 5 0. Entity letter A is not in {P,Q,R,S,W,N}, so the control will be a digit.
Process right-to-left; rightmost digit (0) is doubled first, then alternate.
digit 0 (pos7 from left, doubled): 0*2=0 -> 0
digit 5 (pos6, as-is): 5
digit 8 (pos5, doubled): 8*2=16 -> 16-9=7
digit 1 (pos4, as-is): 1
digit 8 (pos3, doubled): 8*2=16 -> 16-9=7
digit 8 (pos2, as-is): 8
digit 5 (pos1, doubled): 5*2=10 -> 10-9=1
Sum = 0+5+7+1+7+8+1 = 29
D = (10 - (29 mod 10)) mod 10 = (10 - 9) mod 10 = 1
Entity type A renders the digit directly, so control character = '1'.The control character is 1, giving the full CIF A58818501 (VAT form: ESA58818501).
Edge cases
- Entity types P, Q, R, S, W, N always take a LETTER control character (from 'JABCDEFGHI'), never a digit — e.g. control digit D=0 renders as 'J', D=1 as 'A'.
- The 7-digit body may start with 0 (province codes can begin with 0), so the generator draws each of the 7 digits independently 0-9 including the leading one.
- A control digit D=0 maps to the letter 'J' (index 0 of the alphabet), which is why 'J' both appears as a valid entity letter and as a possible control letter.
Gotchas
- The entity letter is NOT fed into the Luhn sum — only the 7 middle digits are. The letter solely determines whether the control is rendered as a digit or as a letter.
- The primitive is plain Luhn: doubled digits over 9 have 9 subtracted (digit-sum), then D = (10 - sum%10) % 10. There is no modulus other than 10 and no external weights array — the doubling pattern comes purely from Luhn's right-to-left alternation over the 7-digit body.
- Because the body is an odd length (7), Luhn's rightmost-first doubling lands on the odd 1-indexed positions from the left; do not assume even positions are doubled.
Parameters
| Parameter | Type | Description |
|---|---|---|
| count | integer1–1000 | Number of records to return, 1–1000 (your plan may lower this). Omitted returns a single record; set it for a batch. |
| edge | boolean | Restrict output to valid edge-case CIFs from the rare corners. |
| extreme | boolean | Return a correct value wrapped in a hostile encoding (untrimmed whitespace, invisible/zero-width characters, BOM, or bidi/combining marks). Homoglyphs are excluded so the value stays machine-parseable; it still validates after normalisation. |
| format | "national" | "vat" | Rendering: bare national CIF (default) or ES VAT number. |
| invalid | boolean | Return a CIF with a deliberately wrong control character. |
| seed | integer | Integer seed for reproducible output: the same seed always yields the same record. |
Response fields
| Field | Type | Description |
|---|---|---|
| value | string | The CIF in the requested format (national or ES VAT). |
| digits | string | The canonical national CIF (letter + 7 digits + control). |
Other generators for Spain
Spanish companySpanish company nameSpanish DNISpanish email addressSpanish IBANSpanish NIESpanish personSpanish person nameSpanish product or service offeringSpanish vehicle registration plate
See all generators for Spain →The same kind of identifier elsewhere
Austrian data · Austrian FirmenbuchnummerAustrian data · Austrian SteuernummerAustrian data · Austrian UIDBelgian data · Belgian OndernemingsnummerBulgarian data · Bulgarian EIKCzech data · Czech IČODanish data · Danish CVRDutch data · Dutch btw-idDutch data · Dutch KvK numberDutch data · Dutch RSINEstonian data · Estonian KMKREstonian data · Estonian registrikoodFrench data · French SIRENGerman data · German HandelsregisternummerGerman data · German Personalausweis numberGerman data · German USt-IdNrGerman data · German Wirtschafts-IdNrHungarian data · Hungarian adószámHungarian data · Hungarian cégjegyzékszámIrish data · Irish CRO numberIrish data · Irish VAT numberItalian data · Italian Partita IVALatvian data · Latvian registracijas numursLithuanian data · Lithuanian įmonės kodasLithuanian data · Lithuanian PVM (VAT) numberLuxembourg data · Luxembourg TVAMaltese data · Maltese identity card numberMaltese data · Maltese VAT numberPolish data · Polish driving licence numberPolish data · Polish ID card numberPolish data · Polish KRS numberPolish data · Polish land and mortgage register numberPolish data · Polish NIPPolish data · Polish passport numberPolish data · Polish REGONPortuguese data · Portuguese Cartão de Cidadão numberRomanian data · Romanian CUI/CIFSlovak data · Slovak IČ DPHSlovak data · Slovak IČOSwedish data · Swedish organisationsnummer
Try it