Barcode InfoPCL FontsHome


Code 128

Home > Barcode Basics > Different Types of Barcodes > Code128

Code 128 provides excellent density for all-numeric data and good density for alphanumeric data. It is often selected over Code 39 in new applications because of its density and because it offers a much larger selection of characters. The Code 128 standard is maintained by AIM (Automatic Identification Manufacturers).

The Code 128 character set includes the digits 0-9, the letters A-Z (upper and lower case), and all standard ASCII symbols and control codes. The codes are divided into three subsets A, B, and C. There are three separate start codes to indicate which subset will be used; in addition, each subset includes control characters to switch to another subset in the middle of a barcode. Subset A includes the standard ASCII symbols, digits, upper case letters, and control codes. Subset B includes standard ASCII symbols, digits, upper and lower case letters. Subset C compresses two numeric digits into each character, providing excellent density.  Here is a sample that contains 12 digits; compare its size to the sample at the top of the page that contains 12 assorted characters:

Each character is 11 times the width of the narrowest bar; using a minimum bar width of 0.010" each character would be 0.11" wide. Using the 0.010" figure, 20 data characters plus start code, check digit, and stop code would measure 2.55" wide (the stop code is 13 times as wide as a narrow bar). Using Subset C with all-numeric data provides 2:1 compression of the data for a total width of 1.45".

Each character consists of 3 bars and 3 spaces, each of which may be 1, 2, or 3 elements wide (1 element = 1/11th of the character width). The bars always use an even number of elements and the spaces use an odd number. This provides the basis for a character-by-character consistency check during scanning. In addition, each Code 128 barcode includes a Modulo 103 checksum.

The Checksum

Calculating the checksum can be a little tricky. Each Code 128 character has a numeric value from 0 to 102. In Subset A and B, the numeric value of a character is its ASCII code minus 32. For instance, a space (ASCII 32) has a value of 0, the exclamation point (ASCII 33) has a value of 1, etc.

Subset A permits printing of ASCII control characters, those with ASCII codes between 0 and 31. For these characters add 64 to the ASCII code to obtain the numeric value. For example, the value of NUL (ASCII 0) is 64, SOH (ASCII 1) is 65, STX (ASCII 2) is 66, etc.

Subset C prints numeric digits in pairs, and the value of the character for checksum purposes is the numeric value of the pair (00, 01, 02... 99).

To calculate the checksum, follow these steps:

  1. Initialize the checksum variable with the value of the start character (103, 104, or 105 for Subsets A, B, or C, respectively).
  2. Initialize a multiplier to 1.
  3. Starting at the left end of the barcode data, add the numeric value of each character times the multiplier to the checksum. Increment the multiplier after each character.
  4. Divide the result by 103. The remainder is the checksum.
  5. Convert the numeric checksum into an ASCII character.

The details of converting the numeric checksum to an ASCII character may vary depending on the particular font being used. Special handling may be required in cases where the resulting ASCII character code equals zero or is above 95.

Generally speaking, in Subset A if the checksum is between 0 and 63 inclusive, add the checksum and the ASCII code for a space (32) to obtain the character code. If the checksum is 64 or higher, subtract 64 to obtain the character code. In Subset B, add the checksum and the ASCII code for a space (32). In Subset C, the checksum is the ASCII value of the character.

See also:
AppNote 001:  Calculating Code 128 Barcode Checksum on FoxPro
AppNote 004:   Calculating a Code 128 Barcode Checksum in Access Basic
AppNote 022:  ASCII Control Codes in Code 128 Barcodes.


(c) Copyright Measurement Equipment Corporation
All Rights Reserved