Tutorial

ISO 6346 Container Number Validation

Container numbers follow the ISO 6346 standard with a built-in check digit. This tutorial explains the format and validation algorithm used across the global shipping industry.

Overview

An ISO 6346 container number consists of 11 characters: a 4-letter owner code (3 letters + equipment category), a 6-digit serial number, and a 1-digit check digit. For example, MSCU1234565 breaks down as owner code MSCU, serial 123456, and check digit 5.

Container number validation is essential for bill-of-lading processing, customs declarations, and terminal operations. A single wrong character can route a container to the wrong yard location or cause customs clearance delays. KabyTech validates container numbers automatically during extraction.

Unlike AWB check digits (modulus-7), container check digits use a modulus-11 algorithm with letter-to-number conversion. This tutorial covers each component and the full validation procedure.

Step 1 — Owner Code (4 Letters)

The first three characters are the owner code, registered with the Bureau International des Containers (BIC). Examples include MSC (Mediterranean Shipping Company), MAE (Maersk), and EGL (Evergreen). The fourth character is the equipment category: U for freight containers, J for detachable equipment, and Z for trailers and chassis.

KabyTech checks extracted owner codes against the BIC registry. Unknown codes are flagged but not rejected, because private and leasing company codes may not appear in the public registry. The equipment category letter is validated to be U, J, or Z.

# Owner code structure
# M S C U 1 2 3 4 5 6 5
# └─┬─┘ │ └────┬────┘ │
#  BIC  cat  serial  check
#
# Common owner codes in Thai freight:
# MSCU — MSC
# MAEU — Maersk
# CMAU — CMA CGM
# EGLV — Evergreen
# OOLU — OOCL
# TCLU — Turkon Container Lines

Step 2 — Serial Number (6 Digits)

The serial number occupies positions 5 through 10 and is always exactly 6 digits, zero-padded on the left. This gives each owner a namespace of one million containers per equipment category — more than enough for even the largest shipping lines.

OCR errors on container serial numbers are common in scanned documents because the numbers are often stenciled on corrugated metal surfaces. Paint degradation, rust, and shadow from corrugation ridges create challenging conditions. KabyTech uses container-specific image preprocessing (contrast enhancement and ridge-pattern suppression) to improve accuracy.

When the serial number cannot be read with high confidence, the API returns multiple candidates ranked by confidence score, allowing your system to attempt validation on each candidate until one passes the check-digit test.

Step 3 — Check Digit (Modulus-11)

The check digit is calculated by converting each of the first 10 characters to a numeric value, multiplying by positional weights (powers of 2), summing the products, dividing by 11, and taking the remainder. If the remainder is 10, the check digit is 0.

# Letter-to-number conversion (ISO 6346)
# A=10, B=12, C=13, D=14, E=15, F=16, G=17,
# H=18, I=19, J=20, K=21, L=23, M=24, N=25,
# O=26, P=27, Q=28, R=29, S=30, T=31, U=32,
# V=34, W=35, X=36, Y=37, Z=38
# (Note: 11, 22, 33 are skipped — multiples of 11)

def validate_container(container_id: str) -> bool:
    """Validate ISO 6346 container check digit."""
    mapping = {}
    val = 10
    for ch in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        if val % 11 == 0 and val != 0:
            val += 1
        mapping[ch] = val
        val += 1
    for i, ch in enumerate("0123456789"):
        mapping[ch] = i

    cid = container_id.upper().replace(" ", "").replace("-", "")
    if len(cid) != 11:
        return False

    total = sum(mapping.get(cid[i], 0) * (2 ** i) for i in range(10))
    check = total % 11
    if check == 10:
        check = 0
    return check == int(cid[10])

Size and type codes (e.g., 20GP for 20-foot general purpose, 40HC for 40-foot high cube, 45R1 for 45-foot reefer) appear separately on the container and shipping documents. KabyTech extracts and validates these against the ISO 6346 size/type code table.

Summary

ISO 6346 container validation involves three components: a 4-letter owner code checked against the BIC registry, a 6-digit serial number, and a modulus-11 check digit with letter-to-number conversion. The algorithm catches any single-character error in the container number.

KabyTech validates container numbers automatically during extraction from bills of lading, customs declarations, and other shipping documents. Failed validations are flagged in the response with candidate alternatives when available, reducing manual correction effort.

Validate container numbers at scale

Automatic ISO 6346 validation on every extracted container ID — across all your shipping documents.