Code 128 Specification

Code 128 is a high-density alphanumeric symbology. Since it was introduced in early 1980s, it has been widely adopted by many industry applications. GS1 derives its retail carton tracking standard GS1-128 (previously known as UCC/EAN-128) based on Code 128 symbology.

Code 128 is capable of encoding all 256 single-byte characters. By default, values above 127 are interpreted as ISO8859-1 characters. It also encodes fours special "function codes" - FNC1, FNC2, FNC3 and FNC4.

Structure of a Code128 Barcode

A typical code 128 barcode has the following structure:

  • A start character

  • Message encoded

  • Check character

  • Stop Character

  • Termination bar (bar+space+bar)

Subtypes

Code 128 includes 107 symbols: 103 data symbols, 3 start codes, and 1 stop code. To represent all 128 ASCII values, there are three code sets (A, B, C), which can be mixed within a single barcode (by using codes 98 and 99 in code sets A and B, 100 in code sets A and C and 101 in code sets B and C to switch between them):

  • 128A (Code Set A) - ASCII characters 00 to 95 (0-9, A-Z and control codes), special characters, and FNC 1-4

  • 128B (Code Set B) - ASCII characters 32 to 127 (0-9, A-Z, a-z), special characters, and FNC 1-4

  • 128C (Code Set C) - 00-99 (encodes each two digits with one code) and FNC1

Start/stop and encoded data

Each character in the barcode symbol is composed of three bars and three spaces. (The stop adds an additional extra bar of length 2.) Each bar or space is 1, 2, 3 or 4 units wide, the sum of the widths of bars must be even, the sum of the widths of the spaces must be odd, and total 11 units per character. For instance, encoding the ASCII value 0 can be viewed as 10011101100, where a 1(One) is a bar and a 0 is a space. A combination which contains a single 1 would be the thinnest line in the bar code. A combination including three 1 (111) in sequence indicates a bar three times as thick as a single 1 bar.

Check Digit Calculation

Every Code 128 symbol requires a check character being placed between encoded data and stop character. The check character is derived from a modulo 103 calculation of the weighted sum of all characters. Here is the procedure to calculate the check character:

  1. Take the value (0 through 102) of each character in the message. This includes the start character, shift character, but excluding the stop character.

  2. Start with the first character of the data, assign the weight for each character. The first character has a weight of 1, the second character has a weight of 2.. and increment by 1. Note that the start character also has a weight of 1. stop character is excluded in the calculation.

  3. Multiply the character value with weight. Sum all the results.

  4. Divide the result by 103 and get the remainder. Look up the remainder in the table to get the check character.

  5. The stop character, and termination bar is appended after the check character.