Validate Swiss AHV number and generate AHV test numbers

What is the Swiss AHV number?

The Swiss AHV number (OASI - Old-age and survivors's insurance) is used as a social security number and as a personal identifier in various areas of Swiss administration. It is a 13-digit random number that does not allow any conclusions to be drawn about a person's data and it remains unchanged for life. The first 3 digits are fixed '756' for Switzerland according to ISO 3166, followed by 9 random digits and a check digit according to EAN-13 to verify the validity of the number.

Every person who lives or works in Switzerland (and is therefore insured under the AHV) is assigned an AHV number. It is printed on the health insurance card. Persons who are not insured under the AHV can also be assigned an AHV number under certain circumstances. Children receive an AHV number as soon as they are registered with a health insurance company, which must happen no later than three months after birth.

Before 2008, there was a 11-digit AHV number, which was then replaced by the 13-digit number. There were too few free numbers and the old AHV number was also problematic for data protection reasons. It was possible to read out, among other data, the date of birth, gender and parts of the name, which also meant that the number did not necessarily remain unchanged for a lifetime. As of July 1, 2008, the new 13-digit, completely anonymous AHV number was therefore introduced.