How can I calculate an IBAN national check digit?

Tostis picture Tostis · Nov 9, 2013 · Viewed 16.3k times · Source

Following Wikipedia, I’m developing a Java application that calculates and verifies IBANs from various countries. Some BBAN have a national check digit, but I can't find any documentation about how to calculate it. Where I can find the algorithm for "national check digit"? I'm not interested in "iban check digit" but on the country related one.

Answer

user3364216 picture user3364216 · Feb 28, 2014

When you need to construct/deconstruct the Spanish Iban, spain is a country which has two sets of check digits, calculated in the order below: 45, 91

ES91 2100 0418 4502 0005 1332

Countrycode (2 characters 'ES') Check digits (2 characters) Bank identifier (4 characters) Branch code (4 characters) check digit (2 characters) Account number (10 characters)

Step-by-step guide 1. First, change the ES to its numeric equivalent E=14, S=28 and append this value with 00, so 142800 Now, to get the first set of iban check digits, add account number to the number from step 1: 0200051332142800

  1. Now mod 97 that value, then subtract the remainder from 98. 0200051332142800 mod 97 = 53, 98 - 53 = 45 <- first set of check digits! (smile)

  2. If you end up with one digit, it should be padded with a leading zero.

  3. To get the second iban check digits, append the bank id(2100) to the branch id(0418) then account number, plus first check digits (450200051332)then the value from step 1, in total: 21000418450200051332142800

  4. Again mod 97 that value, 21000418450200051332 mod 97 = 7, 98 -7 = 91 <- second set of check digits (smile)