- Code 128 Barcode Symbology Overview
- Code 128 Standards
- Printing Code 128 Barcodes
- Encoding Tabs and Return Functions in Code 128 Barcodes
- Reading and Scanning
- The Character Set
- Manual Check Digit Character Calculation Examples
- Font Specifications
- If a scanner is needed, IDAutomation also provides barcode scanner kits.
About the Code 128 Barcode Symbology
The Code 128 barcode is a high-density linear symbology that encodes text, numbers, numerous functions and the entire 128 ASCII character set (from ASCII 0 to ASCII 128.) It is commonly used for several implementations; and is also referred to as ISBT-128, GS1-128, UCC-128, EAN-128 and USS Code 128.
Code 128 contains 106 different printed barcode patterns. Each printed barcode may have one of three different meanings depending upon which of the character sets are being used, with the availability of three different Code 128 start characters to program the initial character set. Functions are also provided in the barcode symbology to switch between character sets and encode Application Identifiers. The Code 128 barcode may be complex to use because of the different character sets, which is the primary reason IDAutomation provides the Code 128 auto function, “Code128( )”, in several of the Font Tools, Components, and Applications.
The complete Code 128 barcode consists of a start character, data digits, a modulo 103 check digit, and a stop character.
Start Character | Data Digits | Check Character | Stop Character |
Ì | CODE-128 | O | Î |
![]() |
The above Code 128 barcode symbol was created with the IDAutomation Barcode Image Generator.
Various Standards for Code 128 Barcode Symbology
Several standards exist that dictate how Code 128 barcodes should be generated for certain implementations; a few of these include:
- GS1-128 (previously known as UCC-128 and EAN-128) is defined by GS1 and used to create several types of barcode symbols that include Application Identifiers. Application Identifiers (AIs) define the purpose of the data in the symbol and how it is to be used.
- ISBT-128 is specifically designed for printing blood product barcode labels. It was developed by the International Society of Blood Transfusion (ISBT) and the Working Party on Automation and Data Processing (WPADP).
- USS Code 128 (Uniform Symbology Specification Code 128) is the published specification for the Code 128 barcode.
- ISS Code 128 (International Symbology Specification Code 128) is the USS Code 128 barcode symbology with a new feature that allows the encoding of extended ASCII characters for non-English languages.
- The Global Trade Item Number (GTIN), or previously known as EAN14, is the product identification structure in the GS1 (EAN/UCC) system. The GTIN is a 14 digit fixed length numeric string, including the indicator digit (or logistic variant), the EAN/UCC company prefix, item reference and check digit. When using the GS1-128 barcode symbology, the data will need to be appended with the Fnc1 character and an Application Identifier of 01. The GTIN should always be stored in databases as a 14-digit number. When the GTIN is represented in UPC-A, UPC-E, GTIN-8 and GTIN-13, as 8, 12, or 13 digits, it should be stored as a 14-digit number by appending zeros to the beginning of the data.
- SSCC-18 is a serialized shipping label specification.
Products for Printing Code 128 Barcodes
Several Barcode Integration Guides are available that suggest various barcode printing options. These integration options should be examined to determine whether to use barcode components, applications, or fonts for the printing of barcodes. A few of the Barcode Integration Guides offered include the following:
- Access
- Crystal Reports
- Excel
- FileMaker
- Open Office & Star Office
- Oracle Reports
- Reporting Services
- C++
- C# .NET
- Visual Basic 6 and VB.NET
- Web Barcode Implementation
Featured Product:
The IDAutomation Universal Barcode Font Advantage Package is a unique product that excels at generating barcode 128 on multiple operating systems and locales, including Double Byte versions of Windows.
Reading & Scanning Code 128 Barcodes
To verify encoded data with an app, IDAutomation offers the Barcode Decoder App & SDK. This app is particularly useful in verifying lower ASCII codes, GS1 data, and UTF-8 Unicode encoding. The SDK is available for Xamarin Visual Studio developers to scan barcodes into custom apps.
The most common method of reading code 128 barcodes into a PC is with a linear barcode scanner. Many of these scanners receive power from the USB port, so no external power supply is required. When a barcode is scanned using keyboard emulation, the data scanned appears at the cursor as if it had been typed from the keyboard.
The USS Code-128 Character Set
IDAutomation provides several font tools, macros, and source code samples that may be used royalty-free with IDAutomation barcode fonts, which automatically format the data being encoded to the barcode fonts. Therefore, references to this character set may not be necessary.
The three character sets listed below are for the Code 128 barcode. In the columns A, B, and C are listed the character or function the barcode scanner will read for the associated symbol. The “ASCII” and “Unicode” columns designate the location where the barcode symbol for the character resides. The column “Char” lists the character that resides at the ASCII location, which is used to print the corresponding symbol. The ASCII location for the space character, stop character and character values 94-105 are applicable only to IDAutomation products including the Code 128 Barcode Fonts. The ISO specification for Code 128 does not specify the location of ASCII and Unicode values for these symbols.
USS Code-128 Character Set
* It is necessary to print the Code 128 space character from ASCII 194 instead of ASCII 32 because some applications do not print a symbol instead of a space character. The ASCII location for the space character, stop character and character values 94-105 are applicable only to IDAutomation barcode products including the Barcode 128 Fonts. Additionally, the characters listed for values 00 and 94-105 are from the Latin-1 codepage. When the Latin-1 codepage is not being used, or when using a Mac, it is suggested to use the Universal Barcode Font Advantage™, which creates Code 128 barcodes as a font in any codepage and operating system.
Code 128 Check Character Calculation Examples
IDAutomation provides several font tools, plug-ins, and source code samples that are free to use with IDAutomation barcode fonts, which will automatically format the start, stop and check characters to the barcode fonts. Therefore, the manual calculations described here are rarely necessary.
The following examples create a barcode with the IDAutomation Code 128 Barcode Fonts in the Latin-1 codepage, which is the default setting in the USA. When the Latin-1 codepage is not being used, or when using a Mac, it is suggested to use the Universal Barcode Font Advantage™, which creates the Code 128 barcode as a font in any codepage and operating system.
The following process is used to determine the value of the check character:
- Reference the character set table to obtain the value of the start character and all data characters.
- Assign a weight to each data character (not the start character, just the data characters.) The weighting starts at 1 and increases by one for each data character.
- Multiply the character values by their weights for the data characters.
- Add these together including the start character, divide by 103 and obtain the remainder.
- Use the character set table to locate the character that has the value of the remainder, use this as the check character.
Calculation Example for Character Set A or B:
The following table is an example of how to obtain the check character for the data “biz” using Code 128 character set B.
Start B | b | i | z | STP | |
weighting | 1 | 2 | 3 | ||
values | 104 | 66 | 73 | 90 | |
totals | 104 | 66 | 146 | 270 |
- Calculate the Total: 104+ (66*1) + (73*2) + (90*3) = 586
- Calculate the Checksum: 586 divided by 103 = 5 remainder of 71. Therefore, the check digit equals a value of 71. The character to print for the value of 71 is “g” or ASCII 103.
- To print the data “biz” as a barcode, the text of ÌbizgÎ is combined with the Code 128 Barcode Fonts.
Calculation Example for Character Set C:
The following table is an example of how to obtain the check character for the number “667390” using character set C.
Start C | 66 | 73 | 90 | SOP | |
weighting | 1 | 2 | 3 | ||
values | 105 | 66 | 7 | 90 | |
totals | 105 | 66 | 146 | 270 |
- Separate the numbers into pair and choose the appropriate character from the character set table that represents the number pair.
- Calculate the Total: 105 + (66*1) + (73*2) + (90*3) = 587
- Calculate the Checksum: 587 divided by 103 = 5 remainder of 72. Therefore, the check digit equals a value of 72. The character to print for the value of 72 is ASCII 104.
- To print the data “667390” as a barcode, the text of ÍbizhÎ is combined with the Code 128 Barcode Fonts.
Calculation Example for Multiple Character Sets:
The following table is an example of how to encode the data “biz” using Code 128 character set B with a switch to character set A for a carriage return function.
Start B | b | i | z | É | m | STOP | |
weighting | 1 | 2 | 3 | 4 | 5 | ||
values | 104 | 66 | 73 | 90 | 101 | 77 | |
totals | 104 | 66 | 146 | 270 | 404 | 35 |
- Calculate the Total: 104 + (661) + (73*2) + (90*3) + (101*4) + (77*5) = 1375
- Calculate the Checksum: 1375 divided by 103 = 13 remainder of 36. The check digit equals a value of 36. The character to print for the value of 36 is “D” or ASCII 68.
Switching Between Sets & Encoding Functions
Encoding functions such as returns and tabs may make data entry tasks easier. Functions are easily encoded with the appropriate ASCII function code. Normally, these characters are not visible unless an application is used such as IDAutomation’s Barcode Scanner ASCII String Decoder or the Barcode Decoder Verification App, which displays these hidden functions as tags.
Easily encode functions with Set A:
Use Character Set A and convert all text data to UPPERCASE. Be careful with this method because anything lowercase in set A will create a function! Then use the letter “i” for a tab and “m” for a return. Other functions can be determined by looking up the column for Code A on the character set chart and choosing the associated character. For example: The following character string in character set A encodes the data “JOHN<tab>SMITH<tab>128-288-6794<return>”.
JOHNiSMITHi128-288-6794m
Using the shift function in Set B:
Use Character Set B and perform a shift to set A to encode tabs, returns and other functions. Then use just the letters “Æi” for a tab and “Æm” for a return where “Æ” is ASCII 198 or Unicode 00C6.
For example:
The following character string in character set B encodes the data “John<tab>Smith<tab>349-128-6794<return>”.
JohnÆiSmithÆi349-128-6794Æm
Manual character set switching:
It is suggested to use character set shift methods (described above) if possible. The following switch methods work with all of IDAutomation’s Code 128 products:
When the character set is A or B, switching between character sets is accomplished by placing the appropriate ASCII code of the switch function from the chart in the data to encode.
For example, if you select Set B and you specify the data “bizÉmiÈfonts.com” (“É” is the switch to set A, “m” is the return and “i” is the tab function and “È” is the switch back to set B according to the chart) as the input for the Code 128 B function, the barcode generated would perform the switch to set A and the function of a return plus a tab when scanned by a barcode scanner.
Functions can also be used without any switching if the character set is already A. For example, if you specify the data “BIZm” (“m” is the function according to the chart) as the input for the Code 128 A function, the barcode scanner would read “BIZ” and then a return function.
It is suggested that Mac users use the Universal Barcode Font Advantage™, which creates Code 128 barcodes as a font in any codepage and operating system.
Automatic Encoding with Code 128 Auto:
Functions may be directly encoded in IDAutomation products by enabling “ApplyTilde” in Code128 Auto, and using the format ~??? to specify the ASCII code of the function. For example, Code~009Bar~013 will encode Code[TAB]Bar[RETURN].
When ApplyTilde is not available, the programming code syntax for the ASCII function code may be used in the formula for the DataToEncode. For example, the following formulas combine two fields in a single barcode with a tab function separator:
Crystal Reports: IDAutomation_Code128 ({Table1.DataField1} & Chr(9) & {Table1.C128})
Microsoft Access: =( [Table1.Field1] & Chr(9) & [Table1.Field2] )
VB .NET: DataToEncode =DataString1 & Chr(9) & DataString2
Java: DataToEncode =DataString1 + (char)9 + DataString2;
Encoding Functions with Set A:
Caution should be used in character set A because any lowercase letter will create a function according to the chart. Use the letter “i” for a tab and “m” for a return. Other functions may be determined by looking up the column for Code A in the character set chart. For example, the following character string in character set A encodes the data “JOHN[tab]SMITH[tab]128-288-6794[return]”:
JOHNiSMITHi128-288-6794m
Code 128 Barcode Font Specifications
IDAutomation Code 128 Barcode Fonts include several sizes to meet various height and width requirements, including GS1-128 sizes. The X dimension (X is the width of the narrow bar) is listed below for various point sizes in millimeters and mils. 1 mil is equal to 1/1000 of an inch. IDAutomation’s Code 128 barcode fonts have been specially designed to be able to produce dependable barcodes when printed at large and small point sizes.
Point Size | Approximate X dimension (1 mil = .001″) | |
48 | .102 cm | 40 mil |
36 | .076 cm | 30 mil |
32 | .069 cm | 27 mil |
30 | .064 cm | 25 mil |
28 | .058 cm | 23 mil |
24 | .051 cm | 20 mil |
20 | .043 cm | 17 mil |
18 | .038 cm | 15 mil |
16 | .033 cm | 13 mil |
12 | .025 cm | 10 mil |
8 | .018 cm | 7 mil |
6 | .013 cm | 5 mil |
* To print at a different X dimension, find the point size that has the X dimension closest to what is needed and use the formula below to find the point size needed:
12 * (X dimension needed) / (X dimension at 12 points) = (point size) For example, to obtain an X dimension of 12 mils, the point size should be 14:
12 * 12 / 10 = 14
When using a printer with less than 600 DPI, print at the following point sizes to create accurate barcodes:
203 DPI Printer (thermal printer) | 300 DPI Printer |
6, 12, 18, 24, 30, 36 | 4, 8, 12, 16, 20, 24, 28, 32, 36 |
The height and N Dimension for each font type is listed in the chart below. Each font may be printed at various point sizes to allow several combinations of heights and widths.
Purchased Font Name | Evaluation Font Name* | Font Height* | N Dimension** |
IDAutomationC128XXS | IDAutomationSC128XXS | .10″ or .254 CM | 10 |
IDAutomationC128XS | IDAutomationSC128XS | .20″ or .508 CM | 20 |
IDAutomationC128S | IDAutomationSC128S | .35″ or .889 CM | 35 |
IDAutomationC128M | IDAutomationSC128M | .50″ or 1.27 CM | 50 |
IDAutomationC128L | IDAutomationSC128L | .60″ or 1.46 CM | 58 |
IDAutomationC128XL | IDAutomationSC128XL | .75″ or 1.90 CM | 75 |
IDAutomationC128XXL | IDAutomationSC128XXL | 1″ or 2.54 CM | 100 |
* Measurements are approximate and were measured when printed at 12 points.
To print at a different height, find the font that has the height closest to what is needed and use the following formula to find the point size that is needed:
12 * (height you want) / (height at 12 points) = (point size converted to integer)
For example, if using IDAutomationC128M and the height is to be .75″, it should be printed at 18 points:
12 * .75 / .5 = 18
** The N Dimension column in the chart is the narrow bar width to font height ratio.