Code 128 barcode generator

The workhorse of shipping labels and internal tracking. Any ASCII character, automatic switching between its three code sets, and a numeric mode that packs two digits into one symbol character, which makes it far tighter than the alternatives on numbers.

Three code sets, chosen for you

Code 128 has three alphabets. Set A covers uppercase and the control characters, set B covers uppercase and lowercase and punctuation, and set C encodes nothing but pairs of digits. A symbol declares which one it starts in and can switch mid-stream as often as it likes.

Picking well matters, because every switch costs a character. This encoder plans the whole string before drawing it and takes set C wherever a run of digits is long enough to repay the switch. You do not choose a code set and you cannot get it wrong.

The density claim, measured rather than repeated

Code 128 is usually described as the densest linear symbology. Measured against this repo's own encoders, that is true for digits and false for letters. Twenty digits: 145 modules here against 217 for Code 93 and 285 for Code 39. Twenty letters: 255 here, and Code 93 needs only 217.

The reason is set C. Two digits per character is a halving that nothing else in the linear family offers, and it is why a long numeric tracking number belongs in Code 128. On letters there is no packing to be had, Code 128's per-character encoding is wider than Code 93's, and the comparison reverses.

So the honest recommendation is: numbers, or mixed content with numbers in it, use Code 128. Uppercase letters only, and width is the constraint, Code 93 is smaller. Anything that has to be read by equipment of unknown age, Code 39, which is the widest and the most universally supported.

The check character is not optional

Every Code 128 symbol carries a modulo 103 check character, computed from the start character and the weighted positions of everything after it. Unlike Code 39, where a check digit is an add-on almost nobody uses, here it is part of the symbology and a reader will reject a symbol whose check character does not agree.

This page computes it. There is no setting for it, because a Code 128 without it is not a Code 128.

Code 128 or GS1-128

GS1-128 is Code 128 with a function character, FNC1, in the first position, and a convention about what follows: standard Application Identifiers that say which field each run of characters is. If you are printing a carton or pallet label that another company's systems will read, that is the one you want.

For a label your own systems read, plain Code 128 and your own format is simpler and has one less thing to get wrong. Both are here.

Questions

Do I need to choose code set A, B or C?

No. The encoder plans the string and switches where switching pays for itself, which is what the specification intends. Choosing by hand mostly produces a wider symbol than necessary.

How long can a Code 128 be?

There is no fixed limit in the symbology, which is the practical problem: it keeps getting wider. Past roughly twenty or thirty characters you are printing something that needs a wide label and a good scan, and a two-dimensional symbology like Data Matrix becomes the better answer.

Can it hold lowercase, spaces or punctuation?

Yes, all of it. Code 128 covers the ASCII range, which is one of the two reasons it displaced Code 39 for new work. Code 39's alphabet is 43 characters with no lowercase at all.

Why is my numeric barcode narrower than a text one the same length?

Because set C packed it. A run of digits encodes two per symbol character, so twenty digits cost about what ten letters cost. That is the mechanism behind the 145 against 255 module measurement above.

Generate a Code 128 →

More barcode generators

Code 39 barcode generator · GS1-128 barcode generator · ITF-14 barcode generator · Data Matrix generator · Aztec code generator · PDF417 generator · Barcode generator · QR code generator

Open the generator → · All formats