Skip to main content
Code 128 is the most widely used general-purpose linear barcode. It can encode any text a keyboard can type, and it packs digits two to a character, so it’s compact for both.

Decode one

Scan or paste a barcode and see every part of it.

Make one

Generate a valid barcode from fields.

Where you’ll see it

  • Shipping labels. Parcel carriers’ tracking numbers are commonly Code 128.
  • Logistics labels in the GS1 form, GS1-128.
  • Inventory, asset and document labels, wherever a business needs letters as well as numbers.

Anatomy

Characters

Every character is 11 modules wide, made of three bars and three spaces, each 1 to 4 modules wide. There are 107 different characters: 103 for data and control, three start codes, and a stop.

Three code sets

The same 103 characters mean different things in each of three code sets: The start code chooses the first code set, and special characters switch between them part way through. An encoder picks the shortest combination, so ABC12345678 is usually encoded as letters in code set B, then the digits in pairs in code set C. You never see any of this in the data. A scanner returns the text, not the code sets.

Size and quiet zones

Code 128 has no fixed size; each application sets its own. The quiet zones are at least 10 modules on each side.

Check character

Every Code 128 barcode ends with a check character, calculated with mod-103 from the start code and every character after it. For ZipZap, it’s the character with value 40. Scanners verify it and then drop it, so it’s never printed or sent, and you only need it to draw a barcode. The calculation is worked through in Check digits.
  • GS1-128: Code 128 with a special character at the start that marks GS1 data.
  • Code 39: older, simpler and less dense, with uppercase letters only.
  • Code 93: a denser successor to Code 39 that never displaced Code 128.

Gotchas

  • A barcode that’s too long to scan. Long text makes a wide barcode. Past a certain width, phone cameras and handheld scanners can’t fit it in view. Consider a QR code for long data.
  • Invisible characters in the data. Code set A can carry control characters, such as a tab or a line break, that won’t be visible when you print the scan. See invisible characters.
  • A Code 128 barcode that’s really GS1 data. If it starts with digits like 01 or 00 and the scanner reports GS1-128, parse it as GS1 data, not as plain text.

Scanning it in your app

Code 128 accepts almost any text, so a pattern is the best way to make sure a scan is the kind of value you expect. See Validation.

Specification

  • ISO/IEC 15417: the Code 128 barcode specification.