On this page
Grab your passport and flip to the photo page. See those two lines along the bottom? Capital letters, a few digits, and a whole row of < symbols that look like someone dozed off on the keyboard.
That's the MRZ. The machine readable zone.
It holds the same core details printed elsewhere on the page: your name, your nationality, your date of birth. The difference is how it's written. Everything sits in a strict, fixed format, so a machine can read it in a fraction of a second.
Why go to all that trouble? Because people shouldn't have to type this stuff. Border officers, airline staff, hotel receptionists, bank onboarding teams... they'd all be keying in names, dates, and document numbers by hand. Typing is slow. And it's where the typos sneak in. A scanner (these days, usually just a smartphone camera) reads the zone, checks it, and hands back clean, structured data.
In this guide, we'll walk through what the MRZ actually contains, the different formats you'll run into, the neat little math trick that catches misreads, and how you can add MRZ scanning to your own app with the barKoder MRZ Scanner SDK.
Let's open it up.
What is an MRZ?
Think of the MRZ as a document's short summary, written for machines instead of people.
It's a standardized block of text printed on passports, national ID cards, visas and residence permits. It covers two things. First, who you are: name, nationality, date of birth, sex. Second, what the document is: its type, the issuing country, the document number and the expiry date. All of it is laid out so OCR (optical character recognition) software can read it without guessing.
Here's the clever part. The format is defined by the International Civil Aviation Organization (ICAO) in Doc 9303, Machine Readable Travel Documents. Every issuing country follows that same rulebook. So one MRZ reader can handle documents from almost anywhere in the world. Pretty handy.
A few rules apply to every MRZ, no matter where it's from:
- Font: OCR-B, a typeface built to be easy for machines to recognize.
- Character set: only capital letters A to Z, the digits 0 to 9, and the filler character <. That's it.
- Fixed positions: every field starts and ends at a set spot on the line. Short values get padded out with <.
- No special characters: accented letters are transliterated (Ü can become UE, for example), and spaces and hyphens in names turn into <.
- Check digits: key fields are followed by a calculated digit that lets software spot a misread. More on these in a minute, because they're the real magic.
MRZ formats: TD1, TD2, TD3 and machine readable visas
Not every MRZ looks the same. A passport booklet and a credit-card-sized ID card are very different shapes, so ICAO defines a handful of layouts. They differ in document size, number of lines and characters per line. The rules they all share live in Doc 9303 Part 3.
Format | Lines × characters | Typical documents |
|---|---|---|
TD3 | 2 × 44 | Passport booklets |
TD2 | 2 × 36 | Medium-sized cards, some visas and older ID cards |
TD1 | 3 × 30 | Credit-card-sized national ID cards, passport cards, residence permits, some driver's licenses |
MRV-A | 2 × 44 | Machine readable visas (full-page size) |
MRV-B | 2 × 36 | Machine readable visas (smaller size) |
The good news? You don't have to pick. The barKoder SDK reads all five formats, MRV-A and MRV-B visas included. One integration, and you've got passports, ID cards, visas and residence permits covered.
Anatomy of a passport MRZ
Let's take one apart. This is the TD3 MRZ from ICAO's specimen passport, issued by the fictional state of Utopia to one Anna Maria Eriksson:
P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<
L898902C36UTO7408122F1204159ZE184226B<<<<<10Line 1: document type, issuer and name
Positions | Field | Specimen value |
|---|---|---|
1–2 | Document type | P< (passport) |
3–5 | Issuing state or organization | UTO |
6–44 | Name: surname, then <<, then given names separated by < | ERIKSSON<<ANNA<MARIA |
See that double <<? That's how a machine knows where the surname ends and the given names begin. Simple, but it works.
Line 2: document and holder data
Positions | Field | Specimen value |
|---|---|---|
1–9 | Document number | L898902C3 |
10 | Check digit (document number) | 6 |
11–13 | Nationality | UTO |
14–19 | Date of birth (YYMMDD) | 740812 (12 August 1974) |
20 | Check digit (date of birth) | 2 |
21 | Sex (M, F or <) | F |
22–27 | Expiry date (YYMMDD) | 120415 (15 April 2012) |
28 | Check digit (expiry date) | 9 |
29–42 | Optional data (often a personal number) | ZE184226B<<<<< |
43 | Check digit (optional data) | 1 |
44 | Overall (composite) check digit | 0 |
Now notice what's missing. There's no address. No place of birth. No photo. The MRZ keeps only what's needed to identify the document and its holder quickly, and nothing more.
How MRZ check digits work
Check digits are what make the MRZ trustworthy. They're like a built-in spell-checker for numbers. Each one is calculated from the field right before it. So if a scanner misreads even a single character, the digit it calculates won't match the one printed on the document. The software notices the mismatch and simply reads again. No guessing, no silent errors. The math is surprisingly simple. It uses a repeating weight of 7, 3, 1:
- Turn each character into a number. Digits keep their value, letters A to Z become 10 to 35, and the filler < becomes 0.
- Multiply each value by its weight, cycling 7, 3, 1, 7, 3, 1 across the field.
- Add the results together.
- Divide by 10. The remainder is your check digit.
Let's try it on Anna's date of birth, 740812:
(7×7) + (4×3) + (0×1) + (8×7) + (1×3) + (2×1) = 49 + 12 + 0 + 56 + 3 + 2 = 122
Divide 122 by 10 and the remainder is 2. Check position 20 on line 2. It's a 2. Match!
Then there's the last digit on the line: the composite check digit. It covers the document number, date of birth, expiry date and optional data all together, their own check digits included. Think of it as the final lock on the door, one last guarantee that the whole line was read correctly.
How MRZ scanning works
Remember those chunky dedicated passport readers bolted to airport counters? You don't really need them anymore. Modern MRZ scanning is just software, and it runs on a phone, a tablet, a kiosk or right in a web browser. Under the hood, it comes down to four steps:
- Detect. The camera finds the document and locates the MRZ on it, even if the card is tilted or half in shadow.
- Read. OCR turns the MRZ characters into text.
- Validate. The software recalculates every check digit. If even one fails, the read is rejected.
- Parse. The validated text is split into labeled fields (surname, given names, document number, nationality, dates, sex) that your app can use straight away.
Here's how barKoder handles it. Machine learning locates the document features in the image first, then OCR reads the MRZ. The parser returns every field, the raw MRZ string and a JSON result. And when it finds them, you also get the corner coordinates of the holder's photo, the signature and the document itself.
Where MRZ scanning is used
Once you start looking, you'll spot MRZ scanning almost everywhere someone needs to check who you are. Basically, anywhere a person would otherwise be squinting at your ID and typing:
- Border control and e-gates: passengers move through faster, with fewer manual entries.
- Airline check-in and boarding: passport details are captured automatically for APIS and security checks.
- Banking and fintech KYC: customers get onboarded in seconds, instead of typing out their ID data on a tiny phone keyboard.
- Hotel and short-term rental check-in: guest registration that keeps up with local reporting rules. Datalab Montenegro, for example, uses barKoder in Lotos Tourist to register guests by scanning their ID documents (read the customer story).
- Car rental, SIM registration and age checks: any counter where an ID has to be recorded accurately, and quickly, while someone waits.
- Access control and self-service kiosks: visitor registration at offices, data centers and events. SerOnuba, for example, scans both MRZ documents and QR codes with a single SDK for access control at its slots parlours (read the SerOnuba story).
- Healthcare: making sure each patient is matched to the right record.
Scanning MRZ with the barKoder SDK
Here's something we love about this: MRZ scanning isn't a separate product you bolt on. It's a decoder inside the barKoder Barcode Scanner SDK. So you read MRZ and barcodes with the very same integration.
The workflow is about as simple as it gets. Turn on the ID document decoder. Point the camera at the document. Read the parsed fields from the result. Done.
What you get:
- Speed. Our MRZ engine got up to 2x faster. Curious how it stacks up? See our MRZ performance test against other SDKs.
- Accuracy. Every check digit is validated before a result comes back. No half-right reads.
- On-device and offline. Document data is processed on the device and never has to leave it. Licensing only needs a periodic check, and offline licenses are available too.
- Every format. TD1, TD2, TD3, MRV-A and MRV-B.
- Images included. On Android and iOS, the SDK can also pull out the document image, the holder's photo and the signature.
- Every platform. Android, iOS, Web (WebAssembly), Windows (C# and .NET) and Linux (64-bit C/C++ library), plus Flutter, React Native, Capacitor, Cordova, .NET MAUI and NativeScript. See all supported platforms and frameworks.
On the web, switching MRZ on takes exactly one line with the barkoder-wasm-ocr package:
Barkoder.setEnabledDecoders(Barkoder.constants.Decoders.IDDocument);Yep, that's really it.
Want the step-by-step? You'll find guides in the documentation for Web, Android, iOS, Flutter and React Native. Already using another MRZ library? Follow our guide to replace MRZScanner SDK with barKoder.
Try it yourself
Reading about it is one thing. Seeing it work is another.
Open the online MRZ reader and scan your own passport or ID card, right there in your browser. It takes a few seconds, and honestly, it's kind of satisfying to watch those two lines of chevrons turn into neat, labeled data.
Ready to build? Start a free 30-day trial (up to 25 devices), check pricing, or talk to an SDK expert about your use case. We'd love to hear what you're working on.



