A Swedish social security number is composed of 10 digits in two groups, 6 and 4 digits each. The groups are separated by a dash (changes to a + when a person is 100 years old or more).
Birth date Checksum
|||||| |
811218-9876
|||
"Birthnumber"
The first 6 digits are the birth date (yyMMdd). The next 3 digits is an identifier where the last digit indicates the persons gender - even numbers for women, odd for men. The last digit is a checksum, calculated using the Luhn algorithm.
Example of applying the algorithm on the social security number above:
8 1 1 2 1 8 - 9 8 7 x
Double every other 16 1 2 2 2 8 18 8 14 x
Sum of digits 7 1 2 2 2 8 9 8 5 =44
This sum you multiply by 9 (44 * 9 = 396) and the last digit, 6 in this case, is your checksum.
PS! This doesn't check for a valid birth date, just the format and checksum.