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.
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
- 1Map each character to a numeric value: 0-9 = 0-9, A-Z (skipping multiples of 11) = 10-38
- 2Multiply each value by 2^(position), where position counts from 0
- 3Sum all products
- 4Take the sum modulo 11
- 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 nowRelated posts
Explore more across carriers, ports, and routes.
What is a Container Number? (BIC / ISO 6346 Explained)
ISO 6346Every shipping container has a unique 11-character identifier. Learn how container numbers are structured, who assigns them, and how to read them at a glance.
Learn moreContainer Tracking for Small Forwarders: A Practical Workflow
ForwardersHow a 3-person freight forwarder can use MariMetric to track 50-200 containers per month, automate client updates, and look bigger than they are.
Learn moreHow to Track an MSC Container: A Complete Guide
MSCStep-by-step guide to tracking any MSC container in real time. Includes MSCU prefix, common status codes, and what to do when MSC's official site blocks automated access.
Learn moreContainer Tracking
Learn how container tracking works and track shipments across every major carrier.
Learn more