Skip to main content

Spanish Company CIF / NIF Generator

Generate and format valid Spanish Company CIF / NIF for software testing and development.

Waiting for generation...

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:

PositionFieldLengthMeaning & RuleExample
1Entity Type1 letterLegal corporate type (e.g., A Corp, B LLC, G Association, P Public Body)B
2 & 3Province2 digitsOfficial INE provincial code (e.g., 28 Madrid, 08 Barcelona, 46 Valencia)28
4 to 8Sequential5 digitsCorrelative entity file number in the province12345
9Control Character1 charComputed digit or letter based on entity category rules7

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. 1. Sum the even-position digits (2nd, 4th, 6th of numeric part): A = d2 + d4 + d6.
  2. 2. Multiply odd-position digits by 2 and take digit sums: B = sum(digit_sum(di * 2)).
  3. 3. Sum total: T = A + B.
  4. 4. Compute check digit: D = (10 - (T % 10)) % 10.
  5. 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].

Frequently Asked Questions & Technical Guidelines