Tutorial

AWB Check-Digit Validation — Modulus-7 Algorithm

Every air waybill number includes a check digit calculated with a simple modulus-7 algorithm. This tutorial explains the format and shows how to validate AWB numbers programmatically.

Overview

An air waybill (AWB) number is an 11-digit identifier consisting of a 3-digit airline prefix and an 8-digit serial number. The last digit of the serial number is a check digit calculated using the modulus-7 algorithm defined in IATA Resolution 600a.

Check-digit validation is a critical quality gate in freight document processing. A misread digit in OCR will almost always produce an invalid check digit, making this a fast and reliable error-detection mechanism. KabyTech validates check digits automatically and flags mismatches in the API response.

This tutorial walks through the AWB number structure, the modulus-7 calculation, and common errors encountered when processing scanned documents.

Step 1 — Airline Prefix (3 Digits)

The first three digits identify the issuing airline. These prefixes are assigned by IATA and are unique to each carrier. For example, 160 is Thai Airways (TG), 235 is Turkish Airlines (TK), and 057 is Air France (AF). The prefix is separated from the serial number by a hyphen in display format but is part of the 11-digit number for validation purposes.

KabyTech maintains an up-to-date database of IATA airline prefixes. When the extracted prefix does not match any known airline, the API flags it as a potential OCR error. This is especially useful for catching digit transpositions in the prefix, which the check-digit algorithm alone cannot detect since it operates only on the serial portion.

# Common airline prefixes in Thai freight
# 160 — Thai Airways (TG)
# 217 — Thai AirAsia (FD)
# 618 — Thai Lion Air (SL)
# 176 — Emirates (EK)
# 235 — Turkish Airlines (TK)
# 014 — Air Cargo Carriers

Step 2 — Serial Number (7 Digits)

The serial number comprises digits 4 through 10 of the AWB number (seven digits). Airlines assign serial numbers sequentially within blocks allocated by IATA. The serial number is the input to the modulus-7 check-digit calculation.

When processing scanned AWBs, the serial number is the most error-prone portion because it contains the most digits and often appears in a dense area of the document. Common OCR errors include confusing 1 and 7, 0 and 8, and 3 and 5. KabyTech's freight-specific OCR model is trained to minimize these confusions, but the check digit provides a final safety net.

Note that the serial number must be treated as a 7-digit integer. Leading zeros are significant — serial number 0012345 is different from 12345 and must retain all seven digits for the check-digit calculation to work correctly.

Step 3 — Check Digit Calculation (Modulus-7)

The check digit is the remainder when the 7-digit serial number is divided by 7. This produces a value between 0 and 6. The check digit occupies the 8th position of the serial portion (the 11th digit overall).

# Worked example
# AWB: 160-12345675
# Airline prefix: 160
# Serial (7 digits): 1234567
# Check digit: 5
#
# Validation: 1234567 mod 7 = 5 ✓
#
# Another example:
# AWB: 176-98765430
# Serial: 9876543
# 9876543 mod 7 = 0
# Check digit: 0 ✓

Here is a Python function that validates an AWB number. It strips the hyphen, extracts the serial and check digit, and verifies the modulus-7 relationship.

def validate_awb(awb: str) -> bool:
    """Validate AWB check digit using modulus-7."""
    digits = awb.replace("-", "").replace(" ", "")
    if len(digits) != 11 or not digits.isdigit():
        return False
    serial = int(digits[3:10])  # 7-digit serial
    check = int(digits[10])     # check digit
    return serial % 7 == check

# Examples
print(validate_awb("160-12345675"))  # True
print(validate_awb("160-12345676"))  # False

Summary

AWB check-digit validation using modulus-7 is a simple but effective quality check for freight document processing. The 3-digit airline prefix identifies the carrier, the 7-digit serial is the dividend, and the check digit is the remainder after division by 7. Any single-digit OCR error in the serial number will be caught by this validation.

KabyTech performs this validation automatically on every extracted AWB number. When the check digit fails, the API returns a check_digit_valid: false flag along with the raw OCR output, so your system can route the document for manual review or attempt re-extraction with enhanced preprocessing.

Let KabyTech validate AWB numbers for you

Automatic check-digit validation on every extracted air waybill — zero configuration required.