Code 128 barcode example
High-Density Linear Symbology

Code 128 Barcode: Code Sets, Switching & Modulo-103 Technical Guide

An engineering reference for Code 128 covering Code Sets A/B/C, start characters, dynamic set switching, numeric compression, FNC characters, weighted Modulo-103 checksum, symbol width, and logistics deployment.

Code Sets
A / B / C
Checksum
Modulo 103
Use Case
Logistics / Internal IDs

1. Why Code 128 Is Dense

Code 128 supports a broad character repertoire while allowing the encoder to change representation strategy inside one symbol. Its strongest density advantage appears when Code Set C packs numeric data in pairs.

To create a Code 128 barcode, use our free online barcode generator and download the result as PNG, JPG, or SVG.

2. Code Sets A, B and C

Set Best For Key Property
A Uppercase/control-heavy data Includes control characters.
B General printable text Supports upper/lowercase printable data.
C Long numeric runs Encodes two digits per codeword.

3. Start Characters and Set Switching

Start A/B/CEncode DataOptional CODE SwitchContinueChecksumStop

An optimized encoder evaluates whether switching sets saves more codewords than the switch itself costs. Blindly encoding all data in Set B can make numeric labels unnecessarily wide.

4. Code Set C Numeric Compression

Each Code C data codeword represents a pair from 00 through 99. Odd-length numeric runs may require a temporary switch or another strategy around the unmatched digit.

Practical consequence

Payload length alone does not determine physical width; the chosen code-set sequence matters.

5. Weighted Modulo-103 Checksum

The checksum begins with the start-code value. Each following symbol value is multiplied by its one-based position, the products are summed, and the result is reduced modulo 103. The checksum codeword is encoded immediately before the stop pattern.

6. FNC Characters and GS1-128 Boundary

Code 128 defines function characters such as FNC1. GS1-128 uses Code 128 as its underlying symbology but adds GS1 rules, including FNC1 and Application Identifier semantics. Arbitrary Code 128 text is not GS1-128.

Do not conflate

Symbology mechanics and GS1 data semantics are separate layers.

7. Width Planning and X-Dimension

Physical width depends on codeword count, X-dimension and quiet zones. Long IDs should be tested against label width and scan distance before a warehouse label format is frozen.

8. Printer and Scanner Engineering

Condition Risk Response
Low-DPI thermal printer Narrow elements merge Increase X-dimension.
Long scan distance Insufficient apparent width Increase symbol size / use suitable optics.
Fast conveyor Motion blur Test at operating speed.
Damaged labels Edge loss Use durable media.

9. Code 128 in Warehouse Systems

WMS IdentifierValidateOptimize Code SetsPrintScanWMS Transaction

The business identifier should originate in the WMS/database. The barcode renderer should never become the system that invents inventory identity.

10. Common Encoder Mistakes

Mistake Result Fix
Set B for long numeric strings Excess width Use Set C where beneficial.
Wrong checksum position Invalid symbol Follow weighted Mod-103.
Calling it GS1-128 Integration mismatch Implement GS1 syntax explicitly.
Over-shrinking Poor print tolerance Size for device resolution.

11. Selection Checklist

Use Code 128 when you need dense alphanumeric internal identification and your scanner fleet supports it. Use EAN/UPC for applicable retail GTIN workflows and GS1-128 when structured GS1 attributes are required.

12. Symbol Values and Stop Pattern

Code 128 maps each codeword to a numerical value. Start codes select the initial code set, data and function codewords follow, then the checksum, and finally the stop pattern. The stop sequence is structurally different from ordinary data codewords and provides a distinct end marker for the decoder.

13. Automatic Encoding Strategy

A production-quality encoder should examine numeric runs, odd/even digit counts, control-character needs, and transition costs. The goal is not simply to choose the shortest visual result at any cost; it is to produce a standards-compliant sequence that remains practical for the target printer and scanner.

14. Application-Level Framing

Code 128 has no inherent concept of SKU, shipment, pallet, or asset. Those meanings belong to the application protocol. Prefixes, delimiters, fixed lengths, or database fields should therefore be documented independently from the barcode symbology so the same business identifier can be migrated later if the carrier changes.

15. Character-Set Switching Cost

Every switch between Code Sets consumes a codeword, so the most compact encoding is not obtained by switching at every opportunity. Encoders should compare the savings from Code Set C numeric compression against the cost of entering and leaving that set. This matters especially for payloads containing short numeric islands inside text, where a switch can make the symbol longer rather than shorter.

16. Scanner Prefixes, Suffixes and Application Parsing

Industrial scanners are often configured to prepend symbology identifiers, append carriage returns, or transform FNC data before transmitting to software. A barcode can therefore decode correctly while the application receives an unexpected string. Document scanner prefixes/suffixes and normalize them deliberately in the application layer rather than hiding those transformations inside ad-hoc operator settings.

17. Code 128 Test Vector Strategy

When validating an encoder, use test vectors that force each important behavior: Set A control characters, Set B lowercase text, Set C numeric pairs, odd-length numeric runs, transitions between B and C, FNC characters where supported, and checksum edge cases. Comparing only the final visual barcode is insufficient; inspect the generated codeword sequence or decode with an independent implementation.

For application testing, verify that the reader transmits exactly the intended payload. Code-set switches and checksum codewords are structural and should not appear as ordinary data. Function characters may be handled specially by scanners, so their transmitted representation must be documented if the receiving application depends on them.

This test-vector approach is especially important when changing barcode libraries. Two libraries can both produce scannable Code 128 symbols yet choose different valid set-switching strategies. That is acceptable as long as the decoded payload is identical and the physical result meets the target print and scan constraints.

2026 Copyright © Qrivio Barcode | All rights reserved.