Blog

How to calculate the MRZ check digit step by step

· 4 min read

To calculate an MRZ check digit, give every character a value (digits keep their value, A to Z count 10 to 35, and the filler < counts 0), multiply the values by the weights 7, 3, 1 repeating from the left, add the products, and keep the last digit of the total. The remainder after dividing by 10 is the check digit. A passport data page has five of these digits on its second machine readable line, and the fifth one covers most of the line.

This article works through all five on a fictional specimen in the style of ICAO's examples. For what each line of the zone contains, read the general MRZ explainer. Here we only do the arithmetic.

The specimen and the rules

The lower line of the specimen, with the upper line omitted, is:

L898902C36UTO7408122F3404148ZE184226B<<<<<12

ICAO Doc 9303 Part 3, section 4.9, describes the method in four steps: multiply each character by its weight, add the products, divide the sum by 10, and take the remainder. Part 4 places the check digits at fixed positions on line 2. Passport number 1 to 9 has its digit at position 10. Date of birth 14 to 19 has its digit at 20. Date of expiry 22 to 27 has its digit at 28. The personal number 29 to 42 has its digit at 43. The composite digit is at 44.

Check digit 1: passport number

Character   L    8    9    8    9    0    2    C    3
    Value      21    8    9    8    9    0    2   12    3
    Weight      7    3    1    7    3    1    7    3    1
    Product   147   24    9   56   27    0   14   36    3
    
    Sum = 316
    316 / 10 = 31, remainder 6, so the check digit is 6

Check digit 2: date of birth

The date 740812 is 12 August 1974 in YYMMDD form.

Character   7    4    0    8    1    2
    Weight      7    3    1    7    3    1
    Product    49   12    0   56    3    2
    
    Sum = 122, remainder 2, so the check digit is 2

Check digit 3: date of expiry

The date 340414 is 14 April 2034.

Character   3    4    0    4    1    4
    Weight      7    3    1    7    3    1
    Product    21   12    0   28    3    4
    
    Sum = 68, remainder 8, so the check digit is 8

Check digit 4: personal number field

Positions 29 to 42 hold ZE184226B<<<<<. The five filler characters count as 0.

Character   Z    E    1    8    4    2    2    6    B    <    <    <    <    <
    Value      35   14    1    8    4    2    2    6   11    0    0    0    0    0
    Weight      7    3    1    7    3    1    7    3    1    7    3    1    7    3
    Product   245   42    1   56   12    2   14   18   11    0    0    0    0    0
    
    Sum = 401, remainder 1, so the check digit is 1

Check digit 5: composite

The composite digit covers positions 1 to 10, 14 to 20 and 22 to 43 of line 2. Those ranges include the passport number, date of birth, expiry date and personal number, each with its own check digit. Positions 11 to 13 (nationality) and 21 (sex) are left out, and so is the composite digit itself. The included characters are joined into one 39-character string, and the weights start again at 7 for its first character.

Block A, positions 1-10:   L898902C36
    Products: 147 24 9 56 27 0 14 36 3 42     Subtotal 358
    
    Block B, positions 14-20:  7408122
    Products:  21 4 0 24 1 14 6               Subtotal 70
    
    Block C, positions 22-43:  340414 8 ZE184226B<<<<< 1
    Products:   3 28 0 4 7 12 8 245 42 1 56 12 2 14 18 11 0 0 0 0 0 1
                                              Subtotal 464
    
    Total = 358 + 70 + 464 = 892
    892 / 10 = 89, remainder 2, so the composite digit is 2

Block B starts at the eleventh character of the joined string, so its weights are 3, 1, 7, 3, 1, 7, 3. Block C starts at the eighteenth, so its first weight is 1. Because the nationality and sex are left out, a wrong nationality code does not change the composite, so check nationality separately against the printed page.

Common mistakes

ScanPass, which is still in development and coming to the App Store, verifies these check digits when it reads a passport, so a misread character is flagged before you save. Until it is available, the arithmetic above is how to check a page by hand. The full rule text is in ICAO Doc 9303 Part 3.