Back to blog
Aug 5, 20265 min read· MariMetric Team

ISO 6346 Container Number Validation: A Developer's Guide

Container numbers have a built-in check digit. Validate them client-side and server-side to catch typos before submitting tracking requests. Code examples in TypeScript and Python.

ISO 6346Container NumberValidationTutorial

The structure of a container number

A standard ISO 6346 container number has 11 characters: 4 letters (owner code + category) + 7 digits (serial + check digit). Example: MSCU1234567, where MSKU is Maersk's owner code.

How the check digit works

  1. 1Map each character to a numeric value: 0-9 = 0-9, A-Z (skipping multiples of 11) = 10-38
  2. 2Multiply each value by 2^(position), where position counts from 0
  3. 3Sum all products
  4. 4Take the sum modulo 11
  5. 5The check digit is 0 if the result is 10, otherwise the result

TypeScript implementation

function validateContainerNumber(num: string): boolean {
  if (!/^[A-Z]{4}\d{7}$/.test(num)) return false;
  const map: Record<string, number> = {};
  "0123456789A BCDEFGHIJ".replace(/ /g, "").split("").forEach((c, i) => {
    map[c] = i;
  });
  let sum = 0;
  for (let i = 0; i < 10; i++) {
    sum += (map[num[i]] ?? 0) * Math.pow(2, i);
  }
  const check = sum % 11;
  const expected = check === 10 ? 0 : check;
  return expected === parseInt(num[10], 10);
}

Why validate?

Up to 5% of manually-entered container numbers have typos. Validating client-side gives users instant feedback and saves you from making 1-3 wasted carrier API calls per invalid input. MariMetric validates on every query — give it a try.

Track a container now

Don't just read about it — try container tracking with a real number from MSC, COSCO, ONE, CMA CGM, or HMM.

Track a container now

Related posts

Explore more across carriers, ports, and routes.