Xerobit

Code 128 Barcode Generator

Enter your data to produce a Code 128 barcode as a scalable SVG. The encoder automatically switches between code sets B and C for the most compact result, calculates the modulo 103 check character, and adds quiet zones. Everything runs locally in your browser; nothing is uploaded.

Barcode

Hello1234567890
  • Encoded text
    Hello1234567890
  • Code set sequence
    B,C
  • Check value
    4
  • Module count
    176

How to use the code 128 barcode generator

  1. Type or paste the ASCII text or numbers you want to encode into the Data field.
  2. Adjust the Bar height slider if you need taller or shorter bars.
  3. Toggle Show human-readable text to include or hide the label below the barcode.
  4. Choose a Background of white or transparent depending on where you will place the image.
  5. Click Generate to render the Code 128 barcode as an SVG you can copy or download.

How Code 128 encoding works

Code 128 encodes each character as a pattern of three bars and three spaces spanning exactly 11 modules. Three code sets cover different character ranges: Set A handles control characters and uppercase, Set B covers printable ASCII (space through tilde), and Set C encodes pairs of digits for maximum density.

A valid symbol always starts with a start character that selects the initial code set, followed by the data characters, a check character, and a stop pattern that is 13 modules wide. The check character is computed using a weighted sum modulo 103. Each data position is multiplied by its one-based index, added to the start code value, and divided by 103; the remainder is the check value.

For example, encoding the letter "A" in Set B: Start B has value 104. The character "A" has value 33 at position 1. The weighted sum is 104 + (33 x 1) = 137. Dividing 137 by 103 gives a remainder of 34, so the check character value is 34.

Automatic switching between code sets B and C

This code 128 barcode generator uses an optimization algorithm that scans the input string for runs of digits. When four or more consecutive digits appear (and the count is even), the encoder switches to Set C, which packs two digits into a single 11-module symbol instead of using two separate symbols in Set B. For odd-length digit runs of five or more, it encodes the first digit in Set B and the remaining even-length portion in Set C.

Switching costs one symbol for the code change command, so it only saves space when the digit run is long enough to offset that cost. Shorter digit sequences stay in Set B to avoid unnecessary switching overhead. The resulting code set sequence is displayed in the output rows so you can verify how the data was encoded.

Module widths and quiet zones

Every Code 128 symbol has a predictable width. Start, each data character, and the check character are 11 modules wide. The stop pattern is 13 modules. The specification requires a quiet zone of at least 10 modules on both the left and right sides, free of any marks or print.

The total module count shown in the results includes these quiet zones. For instance, encoding "A" produces: 10 (left quiet) + 11 (start) + 11 (data) + 11 (check) + 13 (stop) + 10 (right quiet) = 66 modules. In the generated SVG each module maps to a coordinate unit, making the barcode resolution-independent.

Common use cases

Code 128 is widely used in shipping labels, inventory management, and healthcare wristbands because it supports the full ASCII set while remaining compact. Logistics carriers like FedEx and UPS rely on it for tracking numbers. Unlike Code 39, which encodes each character in 12 or more modules without a dedicated digit-packing mode, Code 128 achieves higher density, especially for numeric-heavy data.

If you need a general-purpose tool for multiple symbologies, the barcode generator page covers several formats. For two-dimensional codes, consider the Data Matrix generator or QR code generator instead.

Reference table of character values

The table below shows selected character values used in Set B encoding. These values feed directly into the modulo 103 check calculation.

CharacterSet B valueNotes
Space0Lowest printable ASCII
016Digit zero
925Digit nine
A33Uppercase A
Z58Uppercase Z
a65Lowercase a
~94Highest standard ASCII

In Set C, values 0 through 99 represent digit pairs "00" through "99". Start B is 104, Start C is 105, Code C switch is 99, and Code B switch is 100.

Worked examples

Each result below was produced by the same code the tool runs, so you can check your own numbers against them.

ExampleInputResult
Mixed text and digitsData: Hello1234567890; Bar height (px): 80; Show human-readable text: yes; Background: whiteEncoded text: Hello1234567890; Code set sequence: B,C; Check value: 4; Module count: 176
Pure numeric (uses Set C)Data: 123456789012; Bar height (px): 60; Show human-readable text: yes; Background: whiteEncoded text: 123456789012; Code set sequence: C; Check value: 54; Module count: 121
Short textData: ABC; Bar height (px): 50; Show human-readable text: no; Background: transparentEncoded text: ABC; Code set sequence: B; Check value: 1; Module count: 88
Long digit runData: 00112233445566778899; Bar height (px): 100; Show human-readable text: yes; Background: whiteEncoded text: 00112233445566778899; Code set sequence: C; Check value: 27; Module count: 165

FAQ

What characters does Code 128 support?

Code 128 supports all 128 ASCII characters. Set B covers printable characters from space (32) through tilde (126). Set C covers digit pairs 00 through 99. Set A adds control characters, though this generator focuses on Sets B and C for typical use.

How is the check digit calculated?

The check character uses a modulo 103 algorithm. The start code value is summed with each data character value multiplied by its position index (starting at 1). The total modulo 103 gives the check character value.

Why does the encoder switch between code sets?

Switching to Set C for runs of four or more digits compresses the barcode because Set C encodes two digits per symbol instead of one. This reduces the total number of modules and makes the barcode narrower.

Can I use this SVG barcode for printing labels?

Yes. The SVG output is vector-based and scales cleanly to any print size. Choose the white background option for standard label stock, or transparent if you are overlaying the barcode on a colored surface.

Is my data sent to a server?

No. This code 128 barcode generator runs entirely in your browser. The encoding logic executes locally and nothing is uploaded anywhere.

What is the minimum quiet zone required?

The Code 128 specification requires a quiet zone of at least 10 modules on each side of the barcode. This generator includes those quiet zones automatically in the SVG output.