Guides · Barcode formats
Code 128 Barcode: Structure, Code Sets & Uses Explained
Code 128 is the barcode on almost every shipping label. It can encode letters, digits and special characters while staying especially compact.
Key takeaways
- Code 128 is a linear (1D) barcode that can represent all 128 ASCII characters: uppercase and lowercase letters, digits and control characters.
- It uses three code sets (A, B, C). Code set C encodes two digits per character, which makes purely numeric codes especially short.
- Every Code 128 contains a start character, the data, a check character (modulo 103) and a stop character.
- The standardized variant GS1-128 is used in logistics, for example for SSCC pallet labels, lot numbers and expiration dates.
What is Code 128 used for?
Code 128 is common wherever more than plain numbers need to be encoded, or where a code should be as short as possible:
- Shipping and carriers: tracking numbers on UPS, FedEx and USPS labels
- Amazon FBA: the FNSKU on Amazon labels is a Code 128
- Logistics: the SSCC on pallets and shipping cartons is printed as GS1-128
- Warehouse and inventory: location labels, serial numbers, asset tags for equipment
- Healthcare and manufacturing: lot numbers, expiration dates and production dates
For retail products, on the other hand, the UPC-A or EAN-13 is used, because point-of-sale systems expect a GTIN in that format at checkout. The barcode types comparison gives an overview of all formats.
How a Code 128 barcode is structured
From left to right, a Code 128 consists of these elements:
- Quiet zone: a blank margin on the left (at least ten times the narrowest bar width) so the scanner can detect the start.
- Start character: defines which code set (A, B or C) the code begins with.
- Data characters: the actual information. Shift and code-change characters let you switch between code sets within the code.
- Check character: calculated from all previous characters using the modulo 103 method; it detects read errors.
- Stop character and right quiet zone: mark the end of the code.
Each character is 11 modules wide and consists of three bars and three spaces of varying widths. Only the stop character is slightly longer at 13 modules. The check character is normally not shown in the human-readable text below the barcode.
Code sets A, B and C
| Code set | Contains | Typical use |
|---|---|---|
| Code 128A | Uppercase letters, digits, punctuation and control characters | Legacy systems, control characters |
| Code 128B | Uppercase and lowercase letters, digits, punctuation | Alphanumeric codes such as SKUs or serial numbers |
| Code 128C | Digit pairs 00 to 99 | Long numeric strings, e.g. tracking numbers |
Modern barcode generators choose the code set automatically and switch mid-code when needed. A 12-digit number is represented in code set C with just six data characters, making the barcode about half as wide as with code set B.
How the check character is calculated
Each character has a value from 0 to 102. For the check character, take the value of the start character and add the values of all data characters, each multiplied by its position (1, 2, 3 …). Divide the sum by 103; the remainder is the value of the check character.
Example with code set B for “S2L”: Start B has the value 104. The character values are S = 51, 2 = 18 and L = 44. The sum is 104 + 51×1 + 18×2 + 44×3 = 323. 323 divided by 103 leaves a remainder of 14. So the check character has the value 14 (a period in code set B).
Code 128 vs. GS1-128
GS1-128 (formerly UCC/EAN-128) isn’t a separate symbology but a standardized use of Code 128. Right after the start character comes a special character called FNC1, followed by data with Application Identifiers (AIs): two-digit or longer prefixes in parentheses that say what the following number means:
| AI | Meaning | Example |
|---|---|---|
| (00) | SSCC: Serial Shipping Container Code | (00)340123450000000017 |
| (01) | Product GTIN | (01)04012345000009 |
| (10) | Batch / lot number | (10)L2406 |
| (17) | Expiration date (YYMMDD) | (17)271231 |
The parentheses only appear in the human-readable text below the barcode, not in the code itself. A regular Code 128, by contrast, is free-format and can contain any text.
How to create and scan Code 128
You can create your own Code 128 labels, for example for storage locations, boxes or equipment, for free with the barcode label generator, including sequential numbering. To capture them, an iPhone is all you need: Scan2List: Inventory Scanner detects Code 128 automatically and reads several labels in one photo at the same time, such as a whole stack of packages. You export the list as a CSV to Excel.
For a Code 128 to scan reliably, bar width and print quality need to be right: enough quiet zone, no smudging, no glossy film directly over the code. More tips in Barcode not scanning.
Frequently asked questions
Can Code 128 contain letters?
Yes. With code set B, Code 128 encodes uppercase and lowercase letters, digits and punctuation. Code set A contains uppercase letters and control characters.
How long can a Code 128 barcode be?
The specification doesn’t set a fixed maximum length. In practice, label width and scanners limit the length. GS1-128 is limited to 48 data characters.
What’s the difference between Code 128 and Code 39?
Code 39 is older, doesn’t require a check character and can only represent uppercase letters, digits and a few special characters. Code 128 is more compact, can encode all ASCII characters and has a mandatory check character.
Can I use Code 128 for retail products?
For products scanned at checkout in the US, retailers expect a UPC-A (GTIN-12) from GS1 US. Code 128 is best for internal numbers, logistics and shipping.