Code 128 Format Specification

Complete technical reference for Code 128 barcode symbology, encoding structure, character sets, and GS1-128 standardization.

๐Ÿ“š 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)
โ†’
CHECK
Modulo 103
Checksum
โ†’
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:

# Step 1: Select optimal start character Input: "ABC123" Analysis: Starts with letters โ†’ Use Start B # Step 2: Encode data characters 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 # Step 3: Calculate checksum (see next section) Checksum = 60 # Step 4: Add stop character Stop โ†’ Fixed pattern # Final symbol structure: [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:

  1. Start with the value of the start character (103, 104, or 105 for Start A, B, C)
  2. For each data character, multiply its value by its position (starting at 1)
  3. Sum the start character value and all weighted character values
  4. Divide the sum by 103 and take the remainder
  5. 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:

# Character values 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) # Calculation: Sum = 104 + (40ร—1) + (37ร—2) + (44ร—3) + (44ร—4) + (47ร—5) Sum = 104 + 40 + 74 + 132 + 176 + 235 Sum = 761 # Modulo 103: Check = 761 mod 103 = 39 # Check character value 39 is symbol for 'G' in Set B

Validation Process

When a barcode scanner reads a Code 128 symbol, it:

  1. Decodes all characters including the check character
  2. Recalculates the expected check character using the formula above
  3. Compares the calculated value with the encoded check character
  4. 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:

# Human-readable format: GTIN: 09501101530003 Best Before: Dec 31, 2025 Lot Number: LOT456 Serial Number: SN789012 # GS1-128 encoded format: (01)09501101530003(17)251231(10)LOT456(21)SN789012 # Barcode structure: [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

๐Ÿ“‹ See Also:

External Resources

Tools