How can I calculate an IBAN national check digit?

16,293

Solution 1

The national check digit is defined in national standards, each country having a different standard. Some countries have one check digit, others have two, yet others don't have any.

Spanish bank account numbers for example have two check digits. The first is based on the 4-digit branch and office codes, and the second one is computed from the 10-digit account number. You can find it documented in any document related to banking IT, for example the ones here, but basically you multiply each digit by a power of 2 mod 11, sum the resulting digits together, and take its remainder when divided by 11. The Wikipedia entry has example code for verifying and computing the check digits.

Other countries use other methods, for example the Luhn algorithm.

Solution 2

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)

Share:
16,293
Tostis
Author by

Tostis

Updated on June 07, 2022

Comments

  • Tostis
    Tostis almost 2 years

    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.

  • Tostis
    Tostis over 10 years
    Thanks for your answer but i've already found docs about Italian and Spanish national check digit. Maybe i'll search documentation on institution sites like ABI (IT) or AEB (ES), but i have to find these regulation for each country first.
  • Joni
    Joni over 10 years
    Sounds like you have found your answer then.
  • Tostis
    Tostis over 10 years
    I've found my question ;)
  • Praditha
    Praditha over 6 years
    Where did you get "numeric equivalent E=14, S=28" ..?
  • Joe
    Joe over 6 years
    You cant get the numeric value with a function of java, for example, Character.getNumericValue('a') -> 10
  • OlivierTerrien
    OlivierTerrien over 4 years
    @Praditha, E=14 because ASCII value of character 'E' - 55 = 14
  • Terry Burton
    Terry Burton over 3 years
    This answer calculates the IBAN check digit, not the national BRAN check digit. The BRAN is a component of the overall IBAN and the question relates specifically to this component whose structure is defined by national standards and is not within the purview of the IBAN standard.