Italian fiscal code

The Italian fiscal code, officially known in Italy as Codice fiscale, is the tax code in Italy, similar to a Social Security Number (SSN) in the United States or the National Insurance Number issued in the United Kingdom. 
It is an alphanumeric code of 16 characters. The code serves to unambiguously identify individuals residing in Italy irrespective of residency status. Designed by and for the Italian tax office, it is now used for several other purposes, e.g. uniquely identifying individuals in the health system, or natural persons who act as parties in private contracts.
The code is issued by the Italian tax office, the Agenzia delle Entrate.
In the past, each person in Italy was handed a plastic card with a magnetic strip, bearing the tax code as well as the surname, given name(s), sex, place and province of birth (or country of birth if foreign), date of birth and date of issue. Today, the fiscal code card has been replaced by a combined Italian health insurance card for qualifying residents which shows an expiration date.
Fiscal code generation.
The laws covering the calculation of a fiscal code were put in place by the Ministry of Economy and Finances on December 23, 1976.
For natural persons, the fiscal code is made of 16 alphanumeric characters; for legal persons (e.g. corporations) it comprises 11 numeric-only characters.
While it is possible to calculate one's tax code, the only official tax code is the one provided by the tax office, which avoids cases of identical tax codes (which is a frequent case for people not born in Italy, as in this case the 4-characters town code in the "codice fiscale" is replaced by "Z" followed by a 3-digit country code) as well as cases where a code is incorrect, but still valid (because provided by the tax office).
The algorithm that follows is used to generate natural persons' fiscal codes.
Examples.
Here is the fiscal code of a fictitious Matteo Moretti (male), born in Milan on 8 April 1991:
Here is the fiscal code of a fictitious Samantha Miller (female), born in the USA on 25 September 1982, living in Italy: