>>Alus.it >projects >algoritmo codice fiscale EN IT

Italian fiscal code calculation algorithm

Project made as exercise for " Course of algorithms and advanced programming" at Polytechnic of Turin technical university. Text and software by Alberto Realis-Luc

How it is made an Italian fiscal code?

The Italian fiscal code is an alphanumeric string of 16 characters. In Italy it used as unique ID to identify individuals. Every person has one because the fiscal code is generated by an algorithm that takes as the only inputs: name, surname, date of birth, gender and place of birth of his owner.
The first 15 characters are generated with the data of the owner and the last one it is a sort of check-sum. A fiscal code is made of 7 parts:

  1. three alphabetic characters derived from the surname
  2. three alphabetic characters derived from the names
  3. two digits for the year of birth
  4. one alphabetic character for the month of birth
  5. two digits for the day of birth and the gender
  6. one alphabetic character and three digits for the place of birth
  7. one alphabetic character as control check-sum

Surname

The three letters of the surname part are the first three consonants of the surname. If there are less than three consonants in the surname, after the consonants the algorithm starts to take also the vowels. If there are still missing letters the letter 'X' will be added.
The surnames composed by more than one word will be considered as just one word.

Name

Here the procedure is similar to the one for the surname with the difference that the first and third and forth consonants are taken, if there are less than 4 consonants then the procedure continues exactly like for the surname.
Also here, if the person has more than one name, all the names are considered as one word: all together without spaces.

Year of birth

The two digits for the year of birth are simply his last two digits.

Month of birth

The month of birth is represented by a single letter according to the following table:

No Month Letter
1 January A
2 February B
3 March C
4 April D
5 May E
6 June H
7 July L
8 August M
9 September P
10 October R
11 November S
12 December T

Day of birth and gender

Day of birth and gender are encoded in two digits. For men those two digits are simply their day of birth and for women the algorithm is adding 40 to their day of birth.

Place of birth

The place of birth can be one of the 8100 Italian municipalities or a foreign country. Every place is identified with a code made of one letter and three numbers. Those codes are determined by the Italian Land Registry. The software downloadable at the end of this page contains a file with a list of all those codes for the 8100 Italian municipalities. Regarding the foreign countries there are the codes also for nations not existing anymore like Czechoslovakia or the former East Germany beacuse the year of birth is considered.

Checksum letter

The last charater is the checksum value, it is always a single letter. The algorithm converts the previous 15 characters in numbers, according to the following table, performing the following steps:

  1. Convert numbers and letters in even position.
  2. Convert numbers and letters in odd position.
  3. Sum all the obtained values.
  4. Divide the previus sum by 26.
  5. Determine the reminder of the previous division.
  6. Look-up in the table the correspondent check-sum letter.
Conversion even and odd characters Values of the checksum letter
Character Even value Odd value Remainder Checksum letter
A or 0 (zero) 0 1 0 A
B or 1 1 0 1 B
C or 2 2 5 2 C
D or 3 3 7 3 D
E or 4 4 9 4 E
F or 5 5 13 5 F
G or 6 6 15 6 G
H or 7 7 17 7 H
I or 8 8 19 8 I
J or 9 9 21 9 J
K 10 2 10 K
L 11 4 11 L
M 12 18 12 M
N 13 20 13 N
O 14 11 14 O
P 15 3 15 P
Q 16 6 16 Q
R 17 8 17 R
S 18 12 18 S
T 19 14 19 T
U 20 16 20 U
V 21 10 21 V
W 22 22 22 W
X 23 25 23 X
Y 24 24 24 Y
Z 25 23 25 Z

Downloads

Generator of fiscal codes for Windows

Screen shot of the program CodiceFiscale.exe

Here there is a simple and lightweight generator of Italian tax ID codes for Windows: CodiceFiscale.exe, it is written as Win32 application. No installation needed, just run it. It needs only the file comuni.txt in the same folder from where it will read the municipalities codes. As soon as a fiscal code is calculated, it is automatically copied on the clipboard, so you can directly past it where required.

Calculation of fiscal codes on command line

And here you can download a really simple program written in C to calculate the fiscal code, it is compiled for Linux and Windows.
The program cf (cf.exe for Windows) works, also here, reading the codes of municipalities from the file comuni.txt that so has to be kept in the same folder. The source code is also included in the zip file, so if you find something that can be improved just let me know.

This small program doesn’t pretend anything, it was just an interesting exercise (especially on string and data management) for the university course of: "Algorithms and Advanced Programming".

64 bit versions

On request of an anonymous user, here you can download the 64 bit versions of the previous programs: CodiceFiscale.exe and CF.exe compiled on 64 bit for more recent versions of Windows. Tested on Windows 8.