Skip to the tool
DevToolBench

Code 128 Barcode Generator

Shortest Code 128 barcode for any ASCII text, as SVG or PNG.

16 chars
Code 128 barcode for SHIP-2026-000481
17 symbols · check value 80

Everything runs in your browser. Nothing you type is sent to a server.

Found a bug in this tool? Report it.

Share this tool

What this tool does

This Code 128 barcode generator encodes any ASCII text — letters, digits, punctuation and even control characters such as tab or carriage return — as a scannable Code 128 symbol, and lets you download it as SVG or PNG. It picks the code sets for you, calculates the check symbol, adds the stop pattern and the quiet zones, and shows the exact list of symbol values it used, so you can see why the barcode is the width it is.

The encoder runs in your browser and was written for this page. Before publishing, its output was rendered and read back by an independent barcode reader, covering every printable ASCII character, every control code and all hundred digit pairs.

How to use it

  1. Type the text to encode. The barcode updates as you type.
  2. To include a tab, carriage return or other control code, tick the control-character option and write it in caret notation: ^I is a tab, ^M a carriage return, ^J a line feed.
  3. Choose the bar height and the size in pixels per module, and whether the text appears underneath.
  4. Download the code 128 barcode svg for label software and print layouts, or the PNG for anything that only accepts images.

How the shortest barcode is chosen

Code 128 has three code sets. Set A holds upper-case letters, digits, punctuation and control characters; set B swaps the control characters for lower-case letters; set C encodes two digits in a single symbol. Switching sets costs a symbol, and so does a one-off shift from A to B or back.

Most generators decide with a rule of thumb, such as "switch to C for four or more digits". This one works out the cheapest path through the whole string: at each character it compares staying in the current set, shifting for a single character, and switching, and keeps whichever produces the fewest symbols overall. A tracking number like ABC123456 becomes three letters in set B followed by three digit pairs in set C, and a lone tab in the middle of lower-case text gets a shift rather than two switches.

The code 128 check digit

The check symbol is a weighted sum modulo 103: the start value plus each data value multiplied by its position. It catches misreads that a simple sum would not, such as two symbols swapped. The code 128 check digit is part of the bars but never of the printed text, and scanners remove it before passing the data on, which is why you will not see it on the label.

Code 128 vs Code 39

The honest summary of code 128 vs code 39 is that Code 128 wins on almost everything. It encodes the full ASCII set without escape sequences, packs digits two to a symbol, and always carries a check symbol. For the same data it is usually much narrower. Code 39 survives because it is self-checking without a checksum, trivial to generate with a font, and baked into older defence and automotive standards. Unless a specification names Code 39, choose Code 128.

Related tools

Need identifiers to print on those labels? The UUID generator creates them, and the random number generator draws numeric ones. To see the bytes behind a string, the text to binary converter shows each character's code.

Frequently asked questions

How is the Code 128 check digit calculated?

Every symbol has a value from 0 to 106. Take the value of the start symbol, then add each data symbol's value multiplied by its position — 1 for the first, 2 for the second and so on. The remainder after dividing by 103 is the check symbol. It is encoded as bars like any other symbol but never printed as text, because scanners verify it and strip it.

Why does the barcode for my number look shorter than I expected?

Because runs of digits are packed two per symbol in code set C. A 12-digit order number takes six data symbols instead of twelve, so the barcode is roughly half as wide as it would be in set B. The tool switches into C only when the saving outweighs the extra switch symbol.

Can I put accented letters or emoji in a Code 128 barcode?

No. Code 128 carries ASCII — the 128 characters of plain English text plus control codes. Some systems use a function code to reach Latin-1, but support among scanners is patchy, so the tool refuses non-ASCII input rather than produce a barcode that reads differently on different devices. For Unicode text, use a QR code.

Is this the same as a GS1-128 shipping label?

Not quite. GS1-128 is Code 128 with an FNC1 character after the start symbol and data arranged into application identifiers such as (00) for the shipping container code. This tool produces plain Code 128, which is what warehouse bins, asset tags, tickets and internal labels use.

Which size should I download for printing?

Download the SVG and let your label software scale it: vectors stay sharp at any size. If you need a PNG, choose 8 pixels per module and print at the size the label template expects. Keep the white margin on both sides — ten times the narrowest bar is the minimum a scanner needs.

Related tools

Updated