Spanish Company CIF / NIF Validator
Validate the authenticity, format, and checksum of Spanish Company CIF / NIF.
About Spanish Company CIF / NIF Validation
Validation checks the first organizational letter (must be in the official list), the 7 central digits, and the final control digit or letter.
The checksum multiplies odd positions by 2 (summing product digits if > 9) and even positions by 1. The remainder of a division by 10 defines the control digit (0 to 9 or letters J to I). If the CIF violates the exclusive letter or number rules for its corresponding category, it is marked as invalid.
Anatomy & Structure of Spanish CIF
The Spanish Corporate Tax ID (CIF) consists of 9 alphanumeric characters regulated by AEAT:
| Position | Field | Length | Meaning & Rule | Example |
|---|---|---|---|---|
| 1 | Entity Type | 1 letter | Legal corporate type (e.g., A Corp, B LLC, G Association, P Public Body) | B |
| 2 & 3 | Province | 2 digits | Official INE provincial code (e.g., 28 Madrid, 08 Barcelona, 46 Valencia) | 28 |
| 4 to 8 | Sequential | 5 digits | Correlative entity file number in the province | 12345 |
| 9 | Control Character | 1 char | Computed digit or letter based on entity category rules | 7 |
CIF Validation Algorithm (Modulo 10 with Alternating Weights)
The official AEAT algorithm evaluates the 7 central numeric digits (province + sequential):
D = (10 - ((sum(even) + sum(digit_sum(odd * 2))) % 10)) % 10
- 1. Sum the even-position digits (2nd, 4th, 6th of numeric part): A = d2 + d4 + d6.
- 2. Multiply odd-position digits by 2 and take digit sums: B = sum(digit_sum(di * 2)).
- 3. Sum total: T = A + B.
- 4. Compute check digit: D = (10 - (T % 10)) % 10.
- 5. Depending on entity type letter: types like A, B, E, H require numeric D; types like K, P, Q, S require letter from "JABCDEFGHI"[D].