CIF (Tax Identification Number for legal entities in Spain): How to calculate and validate the digit control


CIF meaning - what does CIF stand for?

I do not normally write in english in this blog, but I was tired to look during hours for this information in english in internet, so I directly translated and put it here in case it can be useful for anyone else.

The Tax Identification Number (NIF) also known as VAT Number is the form of tax identification used in Spain for natural persons (with a national identity document (DNI) or foreigner identification number (NIE). The precedent of the NIF is the CIF, used in legal entities. Royal Decree 338/1990, dated March 9, regulates the composition and manner of use of the NIF, until the entry into force in January 2008 of Royal Decree 1065/2007, of July 27.

In Spain the VAT Number (NIF) can be of 3 types (always 9 digits):

1.- For natural persons:

  • If they are Spaniards, then the NIF is called DNI. The structure is 8 numbers + 1 letter, and you can use this “unofficial” page to calculate control digit and validate it


  • If they are foreigners but residents in Spain , then the NIF is called NIE. The structure is 1 letter + 8 numbers. The letter can ONLY be X, Y and Z. You can use same algorithm as with DNI, so you can use this “unofficial” page


2.- For legal entities:

The NIF is called CIF and here is the algorithm to calculate the control digit. I just translated a good Spanish web site, In this web at the below part you can validate any CIF.


The CIF consists of 9 alphanumeric digits with the following structure:











  • T: Organization type letter (1 alpha/letter digit) indicates the type of the organization for example: A for Public Limited company or B for Limited Liability Company.
  • P: Provincial Code (2 numerical digits), correspond to an identifier of the geographical spanish province in which the organization’s headquarters of the company are located . For example 28 for Madrid or 58 for Barcelona.
  • N: Sequential numbering ( 5 numerical digits) within province determinated for letters P in previous point.
  • C: Control digit (1 digit, letter or numerical). To calculate this control digit:

The operations to calculate this check digit are performed on the seven central digits and are the following:

  1. Add the digits of the even positions. Sum = A
  2. For each of the digits of the odd positions, multiply it by 2 and add the digits of the result. For example .: (8 * 2 = 16 -> 1 + 6 = 7). Accumulate the result. Sum = B
  3. Calculate the sum A + B = C
  4. Take only the last digit of the units of C and subtract it from 10. This result of this subtraction gives us D.
  5. From D the control digit is already obtained. If it is to be numeric it is directly D and if it is a letter it corresponds to the relation:

A = 1, B = 2, C = 3, D = 4, E = 5, F = 6, G = 7, H = 8, I = 9, J = 10 or 0

Example to validate the C.I.F .: A58818501

We know that it is a Public Limited company (T=A) and located in Barcelona (PP = 58).
We use the seven central digits = 5881850

We add the even digits: A = 8 + 1 + 5 = 14

Odd positions:
5 * 2 = 10 -> 1 + 0 = 1
8 * 2 = 16 -> 1 + 6 = 7
8 * 2 = 16 -> 1 + 6 = 7
0 * 2 = 0 -> = 0
We add the results: B = 1 + 7 + 7 + 0 = 15

Partial sum: C = A + B = 14 + 15 = 29

The digit of the units of C is 9. We subtract it from 10 and it gives us: D = 10 – 9 = 1

As the type of organization is A will be number 1, if it was a letter it would have been “A”.

And here a website with the programming in php

Hope it helps. Good luck!!





Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.