Spanish Company CIF / NIF Generator
Generate and format valid Spanish Company CIF / NIF for software testing and development.
About Spanish Company CIF / NIF
The Código de Identificación Fiscal (CIF) was the tax identification number used in Spain for companies and associations. Although officially merged under the corporate NIF label, the term CIF is still widely used in business systems.
This tool generates mathematically valid corporate CIFs. The first letter defines the type of organization (A = Public Limited Companies, B = Private Limited Companies, K = Foreign Entities). The final control character is computed using weighted positions and Modulo 10, resulting in a digit or letter based on rules.
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):
- 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].