2D Barcode
Linear Barcode
Code 128
Code 128
Code 128 is a linear, bi-directional symbology barcode. It is a very effective and reliable barcode which is appended with a checksum digit. Code 128 is capable of encoding high-density data including Full 128 ASCII Character Set. At the beginning, Code 128 was designed to encoding identification into a compact alphanumeric bar code. Now Code 128 has been widely used in many applications such as shipping and packing worldwide. It is also the standard of Automatic Identification Manufacturers (AIM). Code 128 was based on ISO/IEC 15417:2007 before.
Structure of Code 128
There are six physical parts of Code 128. The 6 parts are encoded as a sequence of bars and spaces. Each character in Code 39 consisted of 3 bars and 3 spaces. Width of the bars and spaces could be 1, 2, 3 or 4 modules.
  • Quiet zone (the quiet zone should be at least 10 times the width of the narrowest bar.)
  • One of the three start codes
  • Data symbols encoded
  • Checksum digit
  • Stop character
  • Quiet zone
Encoding Data of Code 128
Code 128 permits the encoding of alphanumeric data and all 128 characters of ASCII. Length of Code 128 is variable. In addition, Latin-1 characters could be encoded by using extended character FNC4. Code 128 contains 107 symbols, including: 103 data symbols, 3 start codes, and 1 stop code. Code 128 is divided into 3 subsets (A, B and C). The 3 starts codes determine the A, B or C subset that displays as follows.
  1. Subset A of Code 128: standard ASCII symbols (0-9, A-Z and control codes), data symbols, upper case letters, and control codes.
  2. Subset B of Code 128: standard ASCII symbols (0-9, A-Z, a-z), digits, upper case letters, and lower case letters
  3. Subset C of Code 128: 00-99 (encodes each two digits with one code) and FNC1
Checksum Digit of Code 128
Numeric values of each Code 128 characters ranges from 0 to 102.

Numeric values of Subest A/B= (ASCII code of Subest A/B) - 32

Briefly, to get the character code, just follow the tips:

In subset A, when checksum is between 0 and 63, add the checksum digit and the ASCII code for a space (32).
When checksum is 64 or higher, subtract 64 and get the result.

In Subset B, add the checksum and the ASCII code for a space (32).

Eg. Numeric values of ASCII 33=(ASCII 33) - 32=1

Numeric values of ASCII 35=(ASCII 35) - 32=3

The numeric value of Subset C is the numeric value of the pair. It is the ASCII value of the character.
Note: Results may be various when convert numeric checksum to an ASCII character when using different barcode-font.

A 103 calculation method is used for the checksum digit calculation. This method is based on summary of values of all encoding digits of the 128 barcode.

Follow the steps to calculate the checksum:

  • Calculate the numeric values of the start character.
  • Calculate the numeric values of the first data followed the start character. Multiply the value with 1 (it's position value).
  • Calculate and multiply the numeric values of the followed digit with it position value in sequence.
  • Divided the value by 103. The remainder is the checksum digit should be appended.
  • End with a stop character.
How to Encode Code 128
The checksum digit, which is necessary for the barcode, must be calculated correct before encoding. Code 128 is encoded in bars and spaces after calculating the checksum digit.
  • In code 128, number "1" represents a "dark" or "bar" section.
  • In code 128, number "0" represents a "light" or "space" section.
  • For example, the numbers 1011 represents a single-wide bar (1), followed by a single-wide space (0), and followed by double-wide bar (11).