Code 128 Explained

Code 128 Sample

Code 128 was developed by Computer Identics in 1981 and has become very popular over the years. This barcode symbology is widely used for warehouse management, in the transport industry (e.g. UPS) and in retail as Code 128 EAN / UCC (This variation is now known as 128 GS1. See Code 128 GS1 for a discussion of Code 128 GS1 but read this page first.)

Code 128 code sets A, B, C and start characters

Three different code sets are defined for Code 128 (dubbed A, B, and C) that determine how the code is interpreted by the barcode scanner. The code sets differ in compactness and encodable character set.

Code 128 A: Partial ASCII set, no lower case, but ASCII control chars (TAB, CR/LF etc.)
Code 128 B: Full ASCII set, no ASCII control chars
Code 128 C: Only digits 0-9, encoded in pairs, very compact code

The code set to use is indicated to the scanner by the start symbol or start character. Also available are various mode switching or shift characters to switch from one set to another within a barcode symbol. Usually the code set selection and switching within a symbol is handled by the barcode software that creates the code.

Accented, diacritic characters, emoji with Code 128

In principle non-ASCII characters like German umlauts (e.g. ÄÖÜ) can be encoded in a Code 128 symbol by using a special character (FNC4). However, this feature is not widely supported. Using a 2D barcode symbology like Aztec or Datamatrix with dedicated support for non-ASCII, emoji or Unicode data might be a better choice.

Check digit calculation for Code 128

Code 128 uses a Modulo 103 checksum algorithm. All characters of a symbol are added up and modulo divided by 103. The remainder is the checksum. For a sample calculation, see the Wikipedia article on Code 128. Usually the barcode software that generates the code will calculate the check digit automatically. The check digit will not be appended to the readable text under the code, likewise it is usually not transmitted by the scanner with the encoded data.

In principle, Code 128 could be created without a check digit, however, all common barcode readers and scanners will expect a symbol to carry a check digit.

Sample Code 128

Purely numeric code, resulting in a Code 128 C symbol:

Code 128 C

Mixed data, resulting in a Code 128 B full ASCII symbol (note the difference in the first three bars that encode the start character or symbol). Also note that this code is wider than the previous example although less data is encoded:

Code 128 B

Mixed data ("ABC<TAB>DEF>"), resulting in a symbol that starts as Code 128 B to encode "ABC", then shifts to Code 128 A to encode the <TAB>, then back to 128 B to encode "DEF":

Code 128 A

When scanning this code, the barcode scanner will put out "ABC", followed by the <TAB>, then "DEF". This can be very useful: Consider a data entry mask with two fields. The <TAB> can be used to move the focus from one field to the next. The fist part of the code ("ABC") would go into the first field, the second part ("DEF") would go into the second field.

Non printable characters (like the <TAB> above) are entered into our Code 128 generators using the tilde notation: You enter the tilde, followed by the three digit ASCII code of the symbol. E.g. to encode a <TAB> into the code you would enter "~009".

Code 128 vs Code 39

Another popular choice to encode alphanumeric characters is Code 39. The biggest advantages of Code 39 is that it can be used without a check digit. On the negative side, the barcode will only natively encode capital characters ("ABC"); small caps can be encoded with Code 39 Extended but this code can get very large, as the following example illustrates:

Code 128 vs Code 39

Likewise, Code 39 does not support compact numerical symbols like Code 128 C and is generally a bad choice for larger amounts of data. For more info see Code 128 vs Code 39.

Code 128 in Excel

The easiest and most straight forward way of creating Code 128 barcodes in Excel is with a barcode font. In order to support the different subtypes of Code 128 and the mandatory check digit, such a barcode font can only be used in conjunction with a barcode add-in for Excel.

Code 128 Decoder

While a Code 128 barcode can be decoded manually, it's more convenient to use an app or an online service:

Result of decoding Code 128 barcode

Image shows the output for the above sample of Code 128 C (encoded data: "1234567890"), using Google Zxing, a free online decoder for Code 128. The "Raw bytes" section of the decoded result consists of eight bytes. The first and last bytes are the start and stop characters. In between are five bytes with the actual data (recall that Code 128 C encodes pairs of characters, i.e. "12", "34", "56" etc.) and the checkdigit.

If you want to try for yourself, here is a 300dpi version of the sample code.

Stand-alone software for Code 128 - Mac

Softmatic BarcodePlus V5 creates Code 128 and will export the barcode as PDF / SVG (resolution-independent vector) oder raster image (PNG, TIFF). The app will automatically select the appropriate 128 subtype:



Free download from Mac App Store.

Stand-alone Software für Code 128 - Windows

Softmatic® BarcodePlus (Win, V4, Windows 7 or higher)

Download

Code 128 mass creation

For batch creation of Code 128 and Code 128 GS1, use Softmatic BarcodeFactory V5. The software will create thousands of barcode symbols in seconds, with data coming from the built-in serial number generator, the clipboard or via import from Excel, Numbers or CSV text files:

Free download on the Mac App Store