Code 128 Explained: Code Sets, Check Character and GS1-128
How does a Code 128 barcode work, and how is GS1-128 different from plain Code 128?
Short answer
Code 128 is a dense linear barcode that encodes letters, digits and symbols by switching between three code sets, and it packs digits two per character in code set C. Every symbol has a start character, a required mod-103 check character and a stop character. GS1-128 is the same symbology with an FNC1 character right after the start, which signals that the data follows GS1 Application Identifier rules.
On this page
Code 128 is the barcode you'll see on shipping labels, warehouse bins, asset tags and work orders. It's compact, it handles both letters and numbers, and label printer languages such as Zebra's ZPL support it directly. If you're choosing a barcode for internal use, it's usually the default answer.
Knowing how it works helps you avoid two common problems: labels that come out longer than they need to be, and GS1-128 labels that scan but deliver garbled data. This guide walks through the structure, the code sets, the check character and the GS1 version.
What Code 128 is
Code 128 is a linear (1D) symbology defined by ISO/IEC 15417. Zebra's ZPL documentation describes it as a high-density, variable-length, continuous, alphanumeric symbology. In plain terms, it can hold short or long data, it fits a lot into a small width, and it can encode the full ASCII character set.
Every Code 128 character is 11 modules wide, where a module is the width of the narrowest bar. Each character is built from three bars and three spaces, each one to four modules wide, according to the GS1 General Specifications. The stop character is the one exception at 13 modules.
Anatomy of a symbol
Reading left to right, every Code 128 barcode has the same parts:
- Left quiet zone, a blank margin. GS1 requires at least 10 modules on each side of a GS1-128; give plain Code 128 at least as much.
- Start character: Start A, Start B or Start C, which sets the first code set.
- Data characters, including any code set switches.
- Check character, which is always present.
- Stop character.
- Right quiet zone.
Because the start, check and stop characters always take 11 + 11 + 13 modules, a plain Code 128 symbol is 11 modules per character plus 35, not counting quiet zones. The scanner doesn't transmit the start, stop or check characters, only the data.
Code sets A, B and C
Code 128 has three code sets. Each one gives its own meaning to the same symbol character values, 0 through 102, while the three start characters and the stop character have patterns of their own.
| Code set | What it encodes | Typical use |
|---|---|---|
| A | Uppercase letters, digits, punctuation and ASCII control characters | Data that includes control characters such as tab or carriage return |
| B | Uppercase and lowercase letters, digits and punctuation (ASCII 32 to 127) | Ordinary text such as SKUs and serial numbers |
| C | Digit pairs 00 to 99, two digits per character | Long runs of numbers |
The symbol switches between sets with special characters. CODE A, CODE B and CODE C change the set for everything that follows, and SHIFT changes between A and B for one character only.
Code set C is what makes Code 128 compact for numbers. A 12-digit number takes 12 characters in code set B but only 6 in code set C. Good encoders switch automatically. Zebra printers in automatic mode, for example, shift to code set C when they see four or more digits in a row.
This is also why you can't make a working Code 128 barcode just by typing text in a barcode font. Something has to choose the code sets and calculate the check character first. Our guide to barcodes in Excel and Google Sheets explains the workaround.
The mod-103 check character
Every Code 128 symbol ends its data with a check character. You can't turn it off; Zebra's documentation notes it is always there. The scanner recalculates it and rejects the scan if it doesn't match.
Here's the method, which the GS1 General Specifications spell out step by step:
- Take the value of the start character and multiply it by 1.
- Multiply each data character's value by its position: 1 for the first data character, 2 for the second, and so on.
- Add all the products.
- Divide by 103. The remainder is the value of the check character.
Worked example: "PB-7" in code set B
In code set B, a character's value is its ASCII code minus 32. Start B has the value 104.
| Character | Value | Weight | Product |
|---|---|---|---|
| Start B | 104 | 1 | 104 |
| P | 48 | 1 | 48 |
| B | 34 | 2 | 68 |
| - | 13 | 3 | 39 |
| 7 | 23 | 4 | 92 |
| Total | 351 |
351 divided by 103 is 3 with a remainder of 42. In code set B, value 42 is the letter J, so the full symbol is Start B, P, B, -, 7, J, Stop.
The J never appears in the human-readable text under the bars, and the scanner doesn't send it to your computer. You only see "PB-7." With four data characters, the symbol is 11 × 4 + 35 = 79 modules wide before quiet zones.
GS1-128: FNC1 and Application Identifiers
GS1-128 is not a different barcode. It's Code 128 with one rule added: a special character called FNC1 placed immediately after the start character. The General Specifications say that FNC1 in that first position is reserved exclusively for the GS1 system, so any Code 128 starting that way is GS1-128, and any that doesn't is not.
Application Identifiers
The data in a GS1-128 is a series of element strings, each led by a GS1 Application Identifier (AI) that says what follows. GS1 publishes the full list in its Application Identifier browser. Common ones include:
| AI | Meaning | Format |
|---|---|---|
| (00) | SSCC, the serial number of a shipment or pallet | 18 digits |
| (01) | GTIN of a trade item | 14 digits |
| (10) | Batch or lot number | Up to 20 characters |
| (17) | Expiration date | 6 digits, YYMMDD |
| (21) | Serial number | Up to 20 characters |
A GS1-128 carrying a GTIN, an expiration date and a lot number would print as (01)00614141999996(17)271231(10)LOT42. The parentheses appear only in the human-readable text; they aren't encoded in the bars.
Order matters for variable-length data
The General Specifications keep a short list of AIs with a predefined length, including (00), (01) and (17), so software always knows where they end. Every other AI, including (10) and (21), needs an FNC1 separator after its data unless it comes last in the symbol. Put the predefined-length fields first and a single variable-length field last, and you need no separators at all.
When a scanner reads a separator FNC1, it sends the ASCII group separator character to your software. If your system shows run-together or garbled GS1-128 data, check that it handles that character and that the scanner is set to send it.
Size limits
GS1 limits a single GS1-128 to 48 data characters. The General Specifications also cap its length at 165.10 mm (6.5 inches) including quiet zones, and recommend starting in code set C when the data begins with four or more digits.
Where GS1-128 numbers come from
The GTIN or SSCC inside a GS1-128 must be built from your GS1 Company Prefix. GS1 US states that GS1-128 barcodes can only be created with GS1 Company Prefix membership. [VERIFY] Lot numbers, dates and serials are yours to assign.
GS1-128 isn't meant for the checkout counter. GS1 US explains that it's used on packaging levels above the retail item and that traditional checkout laser scanners can't read the extra data. For cases that need only a GTIN, ITF-14 is often simpler, as covered in our ITF-14 guide.
Bottom line
Code 128 is the default for internal labels because it's dense, it handles letters and numbers, and its check character is built in. Let your software pick the code sets so numbers land in compact code set C. Use GS1-128 only when the data is GS1 data, with real GTINs or SSCCs and correctly formatted AIs. To make either one, open the barcode generator, choose Code 128 or GS1-128, and type AIs in parentheses for GS1-128.
Sources
- ISO: ISO/IEC 15417:2007 Information technology — Automatic identification and data capture techniques — Code 128 bar code symbology specification
- GS1: GS1 General Specifications Standard
- GS1: GS1 Application Identifiers
- GS1: One-dimensional (1D) barcodes for retail general distribution, healthcare and logistics
- GS1 US: What is a GS1-128 barcode?
- Zebra Technologies: ^BC — Code 128 Barcode (Subsets A, B, and C)