MRZ explained

MRZ is "Machine Readable Zone" - typically on a passport. This "zone" is used by an electronic scanning device. For instance, while crossing a border in an airport, a passport is put into this device and the MRZ is read by a passport-reader.

For technical description, see ISO/IEC 7501-1:1997, ISO/IEC 7501-2:1997, and ISO/IEC 7501-03:1997 or the International Civil Aviation Organization document "ICAO Document 9303".

----Here are the fields of a 2 line MRZ:

Ptiiinnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
#########CbbbYYMMDDCsyymmddCppppppppppppppCX

----

Note:

Fields are padded with sign "<". There are no whitespace in the MRZ. Only letters A through Z, digits 0 through 9, and the filler character < are allowed.

P - Passport

The first letter is "P", designating a passport.

t - Passport Type

The second character can be assigned by the issuing country to distinguish different types of passports. If unused a < is assigned.

iii - Issuing Country

The issuing country or organization, encoded in three characters (based on ISO 3166 alpha-3 codes, used by United Nations Statistics Division)

nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn - Name (uppercase)

The general format is "LAST

                  1. - Document Number

C - Check digit

Check digits are calculated based on the previous field. Thus, the first check digit is based on the passport number, the next is based on the date of birth, the next on the expiration date, and the next on the personal number. The check digit is calculated using algorithm described below.

bbb - Nationality

The issuing country or organization, encoded in three characters.

YYMMDD - Date of Birth

The date of the passport holder's birth in YYMMDD form. Year is truncated to the least significant two digits. Single digit months or days are padded with 0.

s - Sex

Sex of the passport holder, M for males, F for females, and < for non-specified.

yymmdd - Passport Expiration Date

The date the passport expires in YYMMDD form. Year is truncated to the least significant two digits. Single digit months or days are padded with 0.

pppppppppppppp - Personal Identification Number (context - country)

This field is used for national ID (in case the given country supports citizen IDs).

X - Final check digit

This is a check digit for positions 1 to 10, 14 to 20, and 22 to 43 on the second line (nationality and sex are excluded from the check). The check digit is calculated using the following algorithm:

Check Digit Calculations

First, break the input into individual characteres and numbers.

Next, convert non-digits into numbers. A through Z are encoded to 10 through 25. The filler character < is encoded as 0.

< A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

Now, multiply each number by the corresponding weighting. The first digit is multipled by 7, the next by 3, and the next by 1. The pattern then repeats (7, 3, 1, 7, 3, 1, 7, 3, 1, etc).

Add up the results, then divide by 10. The remainder is the check digit.

As a special case, if the personal number on the second line is not used (and thus entirely filled with the filler character <), the check digit for that section can be replaced with the filler character <.

An example for the input AB2134:

Input: A B 2 1 3 4 < < <
Value: 10 11 2 1 3 4 0 0 0
Weight: 7 3 1 7 3 1 7 3 1
Products: 70 33 2 7 9 4 0 0 0
Sum: 70 + 33 + 2 + 7 + 9 + 4 + 0 + 0 + 0 = 125

Division: 125 รท 10 = 12, remainder 5
Check digit value X=5.