“Elfproef” algorithm in C# for the Dutch “Burgerservicenummer”

In the Netherlands everyone has a unique personal number called “burgerservicenummer“.

It’s a 9 digit number that satisfies to an alternative on the so-called elfproef: if the burgerservicenummer is represented by ABCDEFGHI, then 9*A + 8*B + 7*C + 6*D + 5*E + 4*F + 3*G + 2*H + (-1*I) must be a multiple of 11.

The following is a fast integer-based algorithm in C# to validate a burgerservicenummer:

public static bool ValidateElfProef(int value)
	int divisor = 1000000000;
	int total = 0;
	int result = value;
	for (int i = 9; i > 1; i--)
		total += i * Math.DivRem(result, divisor /= 10, out result);

	int rest;
	Math.DivRem(total, 11, out rest);

	return result == rest;

public static bool ValidateElfProef(string value)
	return ValidateElfProef(Convert.ToInt32(value));

5 Responses to “Elfproef” algorithm in C# for the Dutch “Burgerservicenummer”

  1. Roel says:

    But it can start with a zero so an int is not usable and you assume the length is correct.

    • robboxman says:

      Hi Roel,

      It will also work with zero’s in front. When a string with a BSN, like “012345678”, is converted to an int it will get the int value 12345678. The algorithm can also validate nummbers shorter than nine digits.

  2. Markus Obrist says:

    Thanks for the sourcecode!
    I tried your algorithm with the number 755490975, which did not work.
    It needs to be for (int i = 9; i > 0; i–) for it to work,.

    You said it works for numbers shorter than 9 digits, but since it starts with a fixed divisor and digits, it can’t really work if the number is shorter.
    I adjusted it to work also with a different amount than 9 numbers to support general 11-proof, not just for IBAN.

    public static bool ValidateElevenProef(int value)
    int total = 0;
    int result = value;
    int digits = value.ToString().Length;
    int divisor = (int)Math.Pow(10, digits);

    for (int i = digits; i > 0; i–)
    total += i * Math.DivRem(result, divisor /= 10, out result);

    int rest;
    Math.DivRem(total, 11, out rest);

    return result == rest;

    • robboxman says:

      Hello Markus,

      Thank you for your contribution. However my algorithm is a specific version of the 11-proof for the Dutch social security number called BSN, not to be confused with bank account numbers like IBAN. The number 755490975 is not a valid BSN indeed (see also this online BSN check).
      I think your algorithm is the general 11-proof which is suitable for bank account numers.

      • Markus Obrist says:

        I see, sorry for the confusion and thanks for clearing things up!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: