Skip to main content

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:

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