iban
Service icon

IBAN

Stable version 1.0.5 (Compatible with OutSystems 11)
Uploaded
 on 12 January 2023
 by 
5.0
 (1 rating)
iban

IBAN

Documentation
1.0.5

Algorithms


Validating the IBAN

An IBAN is validated by converting it into an integer and performing a basic mod-97 operation (as described in ISO 7064) on it. If the IBAN is valid, the remainder equals 1.The algorithm of IBAN validation is as follows:

  1. Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid
  2. Move the four initial characters to the end of the string
  3. Replace each letter in the string with two digits, thereby expanding the string, where A = 10, B = 11, ..., Z = 35
  4. Interpret the string as a decimal integer and compute the remainder of that number on division by 97

If the remainder is 1, the check digit test is passed and the IBAN might be valid.

Example (fictitious United Kingdom bank, sort code 12-34-56, account number 98765432):

• IBAN:
GB82 WEST 1234 5698 7654 32
• Rearrange:
W E S T12345698765432 G B82
• Convert to integer:
3214282912345698765432161182
• Compute remainder:
3214282912345698765432161182mod 97 = 1

Generating IBAN check digits

According to the ECBS "generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account". The ECBS document replicates part of the ISO/IEC 7064:2003 standard as a method for generating check digits in the range 02 to 98. Check digits in the ranges 00 to 96, 01 to 97, and 03 to 99 will also provide validation of an IBAN, but the standard is silent as to whether or not these ranges may be used.

The preferred algorithm is:

  1. Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid.
  2. Replace the two check digits by 00 (e.g., GB00 for the UK).
  3. Move the four initial characters to the end of the string.
  4. Replace the letters in the string with digits, expanding the string as necessary, such that A or a = 10, B or b = 11, and Z or z = 35. Each alphabetic character is therefore replaced by 2 digits
  5. Convert the string to an integer (i.e. ignore leading zeroes).
  6. Calculate mod-97 of the new number, which results in the remainder.
  7. Subtract the remainder from 98 and use the result for the two check digits. If the result is a single-digit number, pad it with a leading 0 to make a two-digit number.

Modulo operation on IBAN

Any computer programming language or software package that is used to compute D mod 97 directly must have the ability to handle integers of more than 30 digits. In practice, this can only be done by software that either supports arbitrary-precision arithmetic or that can handle 219-bit (unsigned) integers,[Note 2] features that are often not standard. If the application software in use does not provide the ability to handle integers of this size, the modulo operation can be performed in a piece-wise manner (as is the case with the UN CEFACT TBG5 JavaScript program).

Piece-wise calculation D mod 97 can be done in many ways. One such way is as follows:

  1. Starting from the leftmost digit of D, construct a number using the first 9 digits and call it N.
  2. Calculate N mod 97.
  3. Construct a new 9-digit N by concatenating the above result (step 2) with the next 7 digits of D. If there are fewer than 7 digits remaining in D but at least one, then construct a new N, which will have less than 9 digits, from the above result (step 2) followed by the remaining digits of D
  4. Repeat steps 2–3 until all the digits of D have been processed

The result of the final calculation in step 2 will be D mod 97 = N mod 97.

Example

In this example, the above algorithm for D mod 97 will be applied to D = 3214282912345698765432161182. (The digits are colour-coded to aid the description below.) If the result is one, the IBAN corresponding to D passes the check digit test.

  1. Construct N from the first 9 digits of D
    N = 321428291
  2. Calculate N mod 97 = 70
  3. Construct a new 9-digit N from the above result (step 2) followed by the next 7 digits of D.
    N = 702345698
  4. Calculate N mod 97 = 29
  5. Construct a new 9-digit N from the above result (step 4) followed by the next 7 digits of D.
    N = 297654321
  6. Calculate N mod 97 = 24
  7. Construct a new N from the above result (step 6) followed by the remaining 5 digits of D.
    N = 2461182
  8. Calculate N mod 97 = 1

From step 8, the final result is D mod 97 = 1 and the IBAN has passed this check digit test.