Trace
Back to blog

Engineering

Tracking Number Formats Explained: How Carrier Auto-Detection Works

A developer's reference to real-world tracking number formats - UPS 1Z, FedEx digit strings, USPS 20-22 digit codes, S10 UPU codes, and dropshipping prefixes - and how to turn them into reliable carrier auto-detection.

6 August 202612 min read

A tracking number looks like an opaque string, but it is really a small message about where a package lives. Formats encode the carrier, the service, sometimes the origin country, and occasionally a checksum. Learning to read those patterns is the first step toward carrier auto-detection that actually works in production.

This article catalogs the formats developers encounter in real e-commerce data - UPS, FedEx, USPS, DHL, the S10 international standard, and the prefix zoo of cross-border logistics - and shows how to order detection rules so they stay fast, predictable, and honest about uncertainty.

Tracking numbers are clues, not guarantees

The comfortable assumption is that a tracking number points at exactly one carrier. In practice, carriers reuse formats, marketplaces generate numbers before parcels enter a network, and a single parcel can accumulate several numbers as it moves between first-mile, line-haul, and last-mile providers. Treat every number as evidence, not identity.

That mindset shapes the whole detection layer. You want rules that are specific enough to be useful, an explicit fallback for unknown numbers, and metadata that tells callers how confident the match is. A wrong carrier guess is worse than no guess, because it sends the lookup to the wrong place and returns confidently bad data.

UPS: the famous 1Z

UPS package numbers are 18 characters starting with 1Z, followed by a six-character account number, a service indicator, and an eight-digit package identifier with a check digit. The format is stable, globally consistent, and almost never collides with anything else, which makes it the ideal first rule in any detector.

Because the prefix is unique, a simple startsWith check on 1Z is safe. The check digit even lets you validate numbers before spending a lookup, which is handy for catching typos in support tools and checkout flows.

FedEx and the digits-only problem

FedEx numbers are usually 12, 15, 20, or 22 digits with no letters. That simplicity is the trap: pure digit strings also describe USPS and several regional carriers. Detection therefore has to consider length ranges and ordering, and accept that some numbers remain ambiguous until a lookup resolves them.

In practice, 12- and 15-digit numbers lean FedEx for domestic US shipments, while 20- and 22-digit strings lean USPS. A good detector encodes those tendencies as priorities, not certainties, and keeps the carrier field honest when evidence is weak.

USPS, S10, and the international alphabet

Domestic USPS numbers are long digit strings, typically 20 to 22 characters beginning 91 through 94. International mail, meanwhile, follows the UPU S10 standard: two letters, nine digits, and a two-letter country code, like LX123456789CN. The two-letter prefix indicates the service and the suffix indicates the origin country, which is why ePacket, China Post, and dozens of postal operators all share one shape.

S10 even includes a check digit computed modulo 7 over weighted digits, which gives detection layers a rare luxury: a cheap validation that a number is plausibly S10 before you commit to a carrier. Use it to separate 'looks international' from 'definitely malformed'.

Dropshipping prefixes: YT, 4PX, CAIN, SF, and the long tail

Cross-border e-commerce added a whole prefix vocabulary: YT for YunExpress, 4PX and FPXE for 4PX, CAIN or LP for Cainiao, CJPAK for CJ Packet, YW for Yanwen, and SF for SF Express. These are not standards, just vendor conventions, but they are stable enough that prefix matching works well for the carriers that matter most to dropshipping merchants.

The trap is overconfidence. SF is also a common substring, LP appears in several systems, and short prefixes collide with order numbers. Match prefixes against normalized uppercase input, require sensible lengths, and always keep an unknown fallback.

A detection order that stays honest

A robust detector orders rules from most specific to least specific: 1Z for UPS, S10 with country suffix for postal operators, vendor prefixes for dropshipping carriers, then USPS digit bands, then FedEx digit bands, and finally unknown. Unknown is a first-class result: it tells the lookup layer to try its generic sources instead of pretending to know.

Expose the detected carrier alongside the response, not instead of it. Developers debug faster when they can see 'carrier: yunexpress, detected from prefix YT', and products behave better when every layer agrees that a guess is a guess.

Build tracking into your product

Create a Trace account, generate an API key, and test package tracking from the dashboard.