๐ Introduction & History
Code 128 is a high-density, linear barcode symbology capable of encoding the entire 128 ASCII character set.
Developed in 1981 by Computer Identics Corporation, it was designed to overcome the limitations of earlier barcode formats
that could only encode numeric data or a limited set of characters.
Key Advantages: Code 128 offers superior data density compared to Code 39, encoding up to 50% more data
in the same space while supporting the full ASCII character set including uppercase, lowercase, numbers, punctuation,
and control characters.
Why Code 128?
Code 128 was created to meet the growing demand for:
- High data density - More information in less space
- Full ASCII support - Complete character encoding capability
- Flexible encoding - Automatic optimization for different data types
- Error detection - Built-in checksum validation
- Industry standardization - Became ISO/IEC 15417 standard
Modern Usage
Today, Code 128 is one of the most widely used barcode formats globally, serving critical roles in:
๐ฆ Shipping & Logistics
๐ญ Manufacturing
๐ฅ Healthcare (ISBT-128)
๐ Supply Chain (GS1-128)
๐ Inventory Management
๐ฉธ Blood Product Labeling
๐๏ธ Barcode Structure
Every Code 128 barcode follows a precise four-part structure. Each component plays a critical role in ensuring
the barcode can be accurately read and validated.
Complete Code 128 Symbol Structure
START
Selects Character Set
(A, B, or C)
โ
DATA
Encoded Content
(Variable Length)
โ
โ
STOP
Symbol Terminator
& Direction
Component Details
1. Start Character
The start character serves two purposes: it signals the beginning of the barcode and selects the initial character set.
There are three start characters:
- Start A - Begins encoding using Character Set A
- Start B - Begins encoding using Character Set B
- Start C - Begins encoding using Character Set C (numeric pairs)
2. Data Characters
The data section contains the actual information being encoded. Character sets can be switched mid-barcode
using special code characters, allowing optimal encoding of mixed data types.
3. Check Character
A mandatory checksum digit calculated using modulo 103 arithmetic. This provides error detection capability,
ensuring the barcode has been read correctly.
4. Stop Character
The stop character signals the end of the barcode and includes an additional "direction" bar that helps
scanners determine reading direction.
๐ค Character Sets
Code 128's flexibility comes from its use of three distinct character sets, each optimized for different types of data.
The encoder automatically selects the most efficient character set based on the content being encoded.
SET A
Uppercase & Control
Characters:
- Uppercase letters (A-Z)
- Numerals (0-9)
- Punctuation marks
- Control characters (ASCII 00-95)
Best for: Legacy systems, control codes, uppercase-only text
SET B
Mixed Case Text
Characters:
- Uppercase letters (A-Z)
- Lowercase letters (a-z)
- Numerals (0-9)
- Punctuation marks (ASCII 32-127)
Best for: Human-readable text, product descriptions, mixed case content
SET C
Numeric Pairs
Characters:
- Numeric digit pairs (00-99)
- Encodes 2 digits per symbol
- Highest density for numbers
- Requires even number of digits
Best for: Serial numbers, dates, numeric IDs, shipping codes
Character Set Switching
Code 128 includes special switching characters that allow mid-barcode transitions between character sets.
This enables optimal encoding of mixed content:
- Code A, Code B, Code C - Permanent switch to specified character set
- Shift - Temporary single-character switch (Set A โ Set B only)
- FNC1-FNC4 - Function codes for special applications (like GS1-128)
Encoding Optimization: Modern Code 128 encoders automatically analyze the input data and select
the optimal combination of character sets and switching codes to minimize barcode length while maintaining readability.
โ๏ธ Encoding Process
Understanding the encoding process reveals how Code 128 achieves its high data density and flexibility.
Each character in Code 128 is represented by a unique pattern of bars and spaces.
Symbol Patterns
Each Code 128 character consists of:
- 11 modules - The basic unit of width measurement
- 3 bars and 3 spaces - Alternating black and white elements
- Specific width patterns - Each bar/space is 1-4 modules wide
- 106 unique patterns - Enough for all three character sets plus special codes
Encoding Example
Let's encode the text "ABC123" step by step:
Input: "ABC123"
Analysis: Starts with letters โ Use Start B
A โ Value 33 in Set B
B โ Value 34 in Set B
C โ Value 35 in Set B
Code C โ Switch to Set C (Value 99)
12 โ Value 12 in Set C (encodes digits as pair)
3? โ Odd digit, append with encoding in Set B
Checksum = 60
Stop โ Fixed pattern
[Start B][A][B][C][Code C][12][Code B][3][Check 60][Stop]
Optimization Strategies
Advanced encoders use various optimization techniques:
- Look-ahead analysis - Examine upcoming characters to choose optimal character set
- Set C preference - Use Set C for 4+ consecutive digits (50% space savings)
- Minimal switching - Reduce character set changes to minimize overhead
- Shift optimization - Use Shift for single out-of-set characters instead of full switch
โ Checksum Calculation
The Code 128 checksum provides error detection using modulo 103 arithmetic. Every barcode includes a calculated
check character that validators use to verify read accuracy.
Calculation Algorithm
The checksum is calculated using the following steps:
- Start with the value of the start character (103, 104, or 105 for Start A, B, C)
- For each data character, multiply its value by its position (starting at 1)
- Sum the start character value and all weighted character values
- Divide the sum by 103 and take the remainder
- The remainder is the check character value
Formula: Check Character = (Start Value + ฮฃ(Character Value ร Position)) mod 103
Worked Example
Calculate checksum for "HELLO" encoded in Set B:
Start B = 104
H = 40 (position 1)
E = 37 (position 2)
L = 44 (position 3)
L = 44 (position 4)
O = 47 (position 5)
Sum = 104 + (40ร1) + (37ร2) + (44ร3) + (44ร4) + (47ร5)
Sum = 104 + 40 + 74 + 132 + 176 + 235
Sum = 761
Check = 761 mod 103 = 39
Validation Process
When a barcode scanner reads a Code 128 symbol, it:
- Decodes all characters including the check character
- Recalculates the expected check character using the formula above
- Compares the calculated value with the encoded check character
- Accepts the barcode only if they match
๐ GS1-128 Standard
GS1-128 (formerly known as UCC-128 or EAN-128) is a specialized application of Code 128 developed by
GS1 (Global Standards One) for global supply chain and logistics applications. It extends Code 128 with standardized
data structures for encoding complex product and shipment information.
Key Differences from Standard Code 128
- FNC1 Flag Character - Every GS1-128 barcode starts with FNC1 after the Start character
- Application Identifiers (AIs) - Standardized prefixes that define data meaning and format
- Variable vs Fixed Length - AIs specify whether data length is predetermined or variable
- Global Standards - Ensures interoperability across international supply chains
FNC1 Character: The Function Code 1 (FNC1) character signals that the barcode follows GS1 standards
and uses Application Identifiers. This character appears immediately after the Start character in all GS1-128 barcodes.
Application Identifiers (AIs)
AIs are 2-4 digit prefixes that define what data follows and how to interpret it. They enable encoding of
rich metadata about products and shipments.
| AI Code |
Description |
Format |
Example |
| (01) |
Global Trade Item Number (GTIN) |
Fixed 14 digits |
(01)09501101530003 |
| (10) |
Batch/Lot Number |
Variable, max 20 chars |
(10)LOT12345 |
| (17) |
Expiration Date |
Fixed 6 digits (YYMMDD) |
(17)251231 |
| (21) |
Serial Number |
Variable, max 20 chars |
(21)SN987654 |
| (310) |
Net Weight (kg) |
Fixed 6 digits |
(310)000500 = 0.500 kg |
| (400) |
Customer Purchase Order |
Variable, max 30 chars |
(400)PO123456 |
| (420) |
Ship To Postal Code |
Variable, max 20 chars |
(420)94105 |
GS1-128 Example
A complete shipping label barcode might encode:
GTIN: 09501101530003
Best Before: Dec 31, 2025
Lot Number: LOT456
Serial Number: SN789012
(01)09501101530003(17)251231(10)LOT456(21)SN789012
[Start C][FNC1][01][GTIN data in pairs][17][Date][FNC1][10][Lot][FNC1][21][Serial][Check][Stop]
Use Cases
GS1-128 enables critical supply chain functions:
- Traceability - Track products from manufacturer to consumer
- Recall Management - Quickly identify and remove affected batches
- Inventory Control - Track expiration dates and lot numbers
- Shipping Automation - Encode destination, weight, and handling information
- Healthcare - Track pharmaceuticals and medical devices
- Fresh Products - Manage perishable goods with date tracking
Distribution vs Point of Sale: GS1-128 barcodes are designed for supply chain operations and typically
do not pass through retail point-of-sale systems. Consumer products use UPC/EAN barcodes for checkout, while GS1-128
appears on shipping containers, pallets, and cases.
๐ Modern Applications
Industry Variants
Code 128 has evolved into several industry-specific standards, each building on the core symbology:
ISBT-128 (Blood Banking)
The International Society of Blood Transfusion uses ISBT-128 for tracking blood products, plasma, and tissue donations.
This ensures patient safety through complete traceability from donor to recipient.
HIBC (Healthcare)
The Health Industry Bar Code standard uses Code 128 for medical devices, pharmaceuticals, and supplies. It enables
automated inventory management and regulatory compliance in healthcare facilities.
UCC/EAN-128 โ GS1-128 (Supply Chain)
Originally developed as UCC-128 (North America) and EAN-128 (Europe), these were unified under the GS1-128 standard
to create a global supply chain language.
Key Advantages
๐ High Density
๐ค Full ASCII Support
โ
Self-Checking
๐ Flexible Encoding
๐ Global Standards
๐ฑ Wide Scanner Support
When to Use Code 128
Choose Code 128 when you need:
- Alphanumeric data (letters + numbers)
- High data density in limited space
- Full ASCII character support
- Compliance with GS1 standards
- Variable-length data encoding
- Error detection capability
Consider alternatives when:
- 2D codes needed - Use QR Code or Data Matrix for more data capacity
- Retail checkout only - Use UPC/EAN for consumer products
- Ultra-small labels - Consider Data Matrix for tiny spaces
- Damaged environments - QR codes offer better error correction
Scanner Compatibility
Code 128 enjoys near-universal scanner support:
- โ
Laser scanners (omnidirectional and single-line)
- โ
CCD (Charge-Coupled Device) scanners
- โ
Linear imagers
- โ
2D imagers (also reads 2D codes)
- โ
Mobile phone cameras with barcode apps
- โ
Integrated POS systems
๐ Related Documentation
External Resources
Tools