A Code 128 barcode is a high-density, variable-length linear (1D) symbology that can encode the full 128-character ASCII set, making it the standard choice for shipping labels, carton marking, and GS1-128 compliance. Label Toolkit generates Code 128 barcodes natively in the browser, no software to install, and exports them to vector PDF or Zebra ZPL.
- Code 128 encodes all 128 ASCII characters across three subsets (A, B, C) and achieves the highest data density of any alphanumeric 1D barcode.
- Every Code 128 symbol includes a mandatory check digit calculated with a weighted modulo-103 algorithm, so errors in printing are detected automatically.
- Minimum quiet zones are 10 times the narrow bar width (10x) on each side; skipping this causes scan failures more often than any other sizing mistake.
- GS1-128 is a direct application of Code 128 with a Function Code 1 (FNC1) start character added to signal that the data follows GS1 Application Identifier structure.
What does a Code 128 barcode look like?
Every Code 128 symbol is built from the same repeating unit: a module, which is the width of one narrow bar or space. Each encoded character maps to three bars and three spaces, all sized as multiples of 1, 2, 3, or 4 modules. A standard symbol has this fixed structure from left to right:
- Left quiet zone: at least 10 modules of white space (10x the narrow bar width).
- Start character: one of three fixed patterns, Start A (211412), Start B (211214), or Start C (211232), where each digit is a module count.
- Encoded data characters: variable length, one character per three-bar/three-space group, each group exactly 11 modules wide.
- Check character: a single symbol character calculated by the printer or software before the stop bar is drawn.
- Stop character: a fixed 13-module pattern (2331112) shared by all three subsets, followed by a 2-module termination bar.
- Right quiet zone: at least 10 modules of white space.
Total symbol width in millimeters depends on two things: the number of characters in your data and the X-dimension (the width of one narrow module, often called the X-dim). A 20-character Code 128 at a 0.25 mm X-dim measures roughly (20 characters x 11 modules + start + check + stop + both quiet zones) x 0.25 mm, coming out around 18 to 20 mm wide. At the GS1-recommended minimum X-dim of 0.495 mm for retail-adjacent applications, the same string nearly doubles in width.
The three subsets: A, B, and C explained
Code 128 achieves full ASCII coverage by defining three subsets. A decoder always knows which subset is active because the start character and any mid-stream Code A, Code B, or Code C shift commands signal it explicitly.
| Subset | Characters encoded | Best used for | Data density per character |
|---|---|---|---|
| Code A | ASCII 00 to 95 (control codes, uppercase, digits, punctuation) | Labels that must encode non-printable control characters such as FNC1, STX, or ETX | 1 character per 11 modules |
| Code B | ASCII 32 to 127 (all printable ASCII including lowercase) | General alphanumeric strings, part numbers, serial numbers, URLs | 1 character per 11 modules |
| Code C | Digit pairs 00 to 99 (pure numeric only) | Long numeric strings; encodes 2 digits per 11 modules, so a 20-digit number is half the width of Subset B | 2 digits per 11 modules |
A good encoder switches subsets mid-symbol automatically. For example, encoding the string "SHIP-001234567890" would use Subset B for the alphanumeric prefix and shift to Subset C for the trailing digits, cutting symbol width by roughly 30 percent compared to staying in Subset B throughout. Label Toolkit handles this optimization automatically when you drop a Code 128 element onto your label.
How the check digit works
Code 128 uses a modulo-103 check character. The calculation is straightforward:
- Assign the start character its value: Start A = 103, Start B = 104, Start C = 105.
- For each data character, look up its Code 128 value (a standardized table running 0 to 102).
- Multiply each character's value by its position number, where the first data character is position 1, the second is position 2, and so on.
- Sum all those products and add the start character value.
- Divide the total by 103 and take the remainder. That remainder is the check character value, encoded as a symbol character before the stop bar.
Scanners verify this math on every scan. A single-module print defect that changes one bar width typically shifts the character value enough that the check fails and the scanner rejects the read rather than passing a wrong number, which is exactly the behavior you want in a warehouse or at a point of sale.
Quiet zones: the silent rule that kills most scan failures
The quiet zone is the blank white space surrounding the barcode symbol. The GS1 General Specifications require a minimum quiet zone of 10x (ten times the X-dimension) on both the left and right sides of a Code 128 symbol. At a 0.25 mm X-dim that is 2.5 mm per side. At a 0.495 mm X-dim it is 4.95 mm per side.
The quiet zone is measured from the outermost bar edge, not from the edge of any printed border or background. Cutting it short by even 1 to 2 mm is the single most common reason scanners intermittently fail on labels that look fine to the eye. If you print a border box around your label, make sure no side of that box encroaches on the quiet zone.
Code 128 vs other 1D symbologies
| Symbology | Character set | Max data density | Variable length? | Check digit? | Typical use |
|---|---|---|---|---|---|
| Code 128 | Full ASCII (128 chars) | High (especially Subset C) | Yes | Yes (mod 103) | Shipping, logistics, GS1-128 |
| Code 39 | 43 characters (uppercase, digits, limited symbols) | Low (3 wide elements per char) | Yes | Optional | Legacy industrial, automotive |
| ITF-14 | Digits only | Medium | Fixed 14 digits | Yes (mod 10) | Cartons, case-level GTINs |
| UPC-A | Digits only | Medium | Fixed 12 digits | Yes (mod 10) | US retail point of sale |
| EAN-13 | Digits only | Medium | Fixed 13 digits | Yes (mod 10) | International retail POS |
The practical conclusion: choose Code 128 whenever your data includes letters, mixed alphanumerics, or long digit strings where width matters. Choose UPC-A or EAN-13 only for retail shelf items scanned at a register; those formats are fixed-length by standard. For a broader comparison of all major symbologies, the complete guide to barcode types covers every format in the same depth.
GS1-128: Code 128 with structured data
GS1-128 (formerly called UCC-128 or EAN-128) is Code 128 with one rule added: the symbol must begin with a Function Code 1 (FNC1) character immediately after the start character. That FNC1 acts as a flag telling any GS1-compliant scanner that what follows is a sequence of GS1 Application Identifiers (AIs).