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
- Type the text to encode. The barcode updates as you type.
- To include a tab, carriage return or other control code, tick the control-character option and
write it in caret notation:
^Iis a tab,^Ma carriage return,^Ja line feed. - Choose the bar height and the size in pixels per module, and whether the text appears underneath.
- 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.