Code 128 Barcode Generator

Code 128 is the barcode to reach for when nobody has told you which barcode to use: serial numbers, asset tags, tickets, shelf labels, shipping references. It encodes any printable ASCII text, packs digits two to a symbol character, and every modern scanner reads it. Type below — the readout explains which of its three code sets your characters force. The rules behind that readout, and how they compare with Code 39's fixed alphabet, are laid out in the guide Code 128 code sets and the Code 39 charset .

Code 128

Code 128 settings

Printable ASCII characters (letters, digits, punctuation, space). 1–80 characters.

The check-digit readout appears here once a barcode is generated.

Enter content above to generate a barcode.

Output options

Both presets retain the required quiet zones and must pass the independent decoder before downloads are enabled.

Hiding the text changes only the caption. The bars still encode the same validated value.

For scanning and print, prefer PNG, SVG, PDF, or EPS — JPEG compression can soften bar edges. ZPL downloads as a text file of native printer commands, not an image. Need a different image format? Convert the PNG at fileconverters.ai.

Before print or production use: test the downloaded barcode with your own scanner or scanner app. This tool verifies the mathematics (check digits, character sets) and the rendered bars — it cannot verify your printer's contrast, size, or quiet-zone reproduction.

Guide: Code 128 code sets and the Code 39 charset walks through this analysis character by character, with the full Code 39 alphabet beside it. All guides are listed at /guides/.

The three code sets, in plain terms

Code 128 is really three alphabets sharing one set of bars, and the encoder may switch between them mid-symbol:

  • Code set A — uppercase letters, digits, punctuation, and the ASCII control characters (tab, carriage return…). Control characters are the only thing A has that B lacks, and they are what force a symbol into A.
  • Code set B — uppercase, lowercase, digits, and punctuation. Any lowercase letter in your input forces set B, because A simply has no lowercase.
  • Code set C — digits only, packed two per symbol character. This is the compression trick: a run of digits in set C takes half the width it would in A or B, which is why an encoder jumps to C for runs of four or more.

The analyzer behind the readout belongs to this site's verification layer, not to the renderer. It records four facts about your text — whether every character is printable ASCII and which are not, whether a lowercase letter forces code set B, whether the input is digits only with an even count (pure code set C), and the longest run of consecutive digits — and writes one sentence of guidance. The methodology page fixes the division of labour: the analysis of "which characters force set A or B, when set C compression applies" is offered "as validation and advice; the actual code-set optimization inside the symbol is the renderer's, following the same rules."

Which characters force what is probed, not typed: at build time this page asks the analyzer about every single-character input from code point 0 to 255. It accepts 95; of those, 26 raise the lowercase flag that forces set B, 10 count toward a digit run, and the other 59 — uppercase letters, space, punctuation — force nothing. Control characters, the only thing that would force set A, lie outside the accepted range.

The sentences the readout can say

For an accepted input the analyzer picks one of 5 sentences, tested in a fixed order — even digit count; odd digit count; lowercase present; uppercase text with a digit run long enough to pay for a switch to set C; anything else. One fictional input per branch:

40456789000124 (digits only, even count) → “All digits with an even count — encoded in code set C, two digits per symbol character (the most compact case).”

4045678900012 (digits only, odd count) → “All digits with an odd count — mostly code set C, with one digit carried in code set A or B; adding a leading zero would make it fully paired.”

serial-x (a lowercase letter present) → “Contains lowercase letters, which only code set B provides — the encoder will use code set B (switching to C for long digit runs).”

INV-20260725 (uppercase with a long digit run) → “Uppercase text with digit runs — code set B (or A) for the text, switching to code set C where four or more digits run consecutively.”

AB12-CD3 (uppercase with short digit runs) → “Uppercase letters, digits, and punctuation — encodable in code set A or B; the encoder picks whichever minimizes symbol length.”

Computed at build time by the analyzer the generator runs in your browser, so the page cannot drift from the code.

When an input qualifies twice, the order decides: the fictional lot-20261005 has a lowercase letter and a run of 8 digits, and gets the lowercase sentence. Two more fictional inputs show that a run is an unbroken stretch: in 12-345-6789 the longest is 4, because a hyphen ends one; in 1a2b3c it is 1, because every letter resets the count. The odd-count sentence recommends a leading zero because set C carries digits in pairs, but the analyzer never inserts it: a padded value is a different value. The guidance predicts from the published rules; it does not describe where the renderer switched sets.

What the validator does with your text, in order

Every generator here runs the same four steps before the renderer is called — normalize, enforce, compute or verify, report — and for Code 128 each has an unusual shape.

Normalize — nothing. Code 128 is the one symbology here whose validator changes no character. The EAN family strips spaces and hyphens, and Code 39 uppercases and says so; Code 128 does neither, because every printable character, space included, is data. The fictional input " padded " leaves validation as a payload of 8 characters.

Enforce — printable ASCII and a length cap. The accepted range runs from code point 32, the space, through 126, the ~. The cap is probed the same way, with ever-longer input: 80 characters are accepted and one more is refused — this tool's rule, not the symbology's.

Compute or verify — nothing visible. Code 128 carries no check digit you can type, so the checkDigit field of the validated payload is absent and the cross-check that re-derives the check digit of any validated payload carrying one passes trivially, returning true. The symbol's own mod-103 check character is the renderer's, computed inside the bars and never shown; anything you type is data.

That has a consequence worth seeing. Take the cited published EAN-13 vector 5901234123457 and a copy with its last digit changed, 5901234123458. The EAN-13 validator verifies the first and refuses the second: “Check digit mismatch: for 590123412345 the final digit must be 7, but you entered 8. Fix the number, or enter only the first 12 digits to have the check digit computed.” The Code 128 validator accepts both with the odd-count sentence above, because to it the digits are text. A GTIN's check digit is verified in the EAN, UPC, or ITF-14 generator, and encoding a product number here does not allocate or license it — see Do I need a GS1 barcode?

Report — one note. For the generator's own default example input BG-2026-0001 (not a published vector) the validator returns the payload unchanged and exactly one note, the guidance: "Uppercase text with digit runs — code set B (or A) for the text, switching to code set C where four or more digits run consecutively."

What this tool deliberately refuses

Control characters and accented text are rejected with an explanation, not encoded. Full Code 128 can carry both (sets A and FNC4 respectively), but FNC4 in particular is honored inconsistently by real-world scanners — the same label can read as café on one device and café on another. A generator that hands you that label without warning is not doing you a favor. If you need non-ASCII text scanned reliably, use a QR code, which carries UTF-8 by design.

The validator's real messages, each on a fictional input:

AB, a tab character, CD:

“This tool encodes printable ASCII only — it cannot encode control character U+0009. Full Code 128 can carry control characters and accented text via special conventions, but supporting them halfway would produce codes that scan differently across devices.”

81 characters, one over the cap:

“This tool caps Code 128 input at 80 characters — longer symbols become too dense to print and scan reliably at ordinary sizes.”

How to read them: the first names each offending character once, in order of first appearance, and a control character by its code point rather than an invisible glyph. The character check runs before the length check, and nothing is repaired — what the symbology cannot carry is reported, never rewritten.

Verified before you download it

After validation, the actual SVG shown on the page is rasterized and decoded by ZXing, an engine independent from JsBarcode, and the preview and download controls stay withheld under one of 2 reasons the verification code names explicitly:

  • decode-failed — when the independent reader cannot read the rendered bars.
  • payload-mismatch — when it reads a different text from the validated payload.

For Code 128 the comparison is exact — UPC-A and EAN-13 share one leading-zero equivalence (the same printed symbol under two names), but Code 128 has no alias — so on the padded example a decoded reading of the same text returns true and a reading with both spaces stripped returns false, withholding the barcode. What none of it can verify is print quality: no browser check can certify ink, substrate, scaling, contrast, or quiet zones after printing, so a physical production sample must still be scanned. See How the verifier decodes what you see .

What the ZPL download carries

The ZPL download is a text file of native printer commands, not an image. For the validated payload BG-2026-0001 the export engine's first note reads: “Subset selection is left in automatic mode — the printer picks Code 128 subsets.” One transport limit: ^ and ~ are ZPL control characters and cannot travel inside the field data, so although the validator accepts the fictional AB^CD, the ZPL export refuses it: “Code 128 ZPL export cannot carry "^": ^ and ~ are ZPL control characters inside ^FD data. This is a ZPL transport limitation, not a barcode limitation — the symbology itself can encode them, but this export cannot transmit them safely.” See the ZPL and EPS export guide.

Quiet zones and sizing

Like every linear barcode, Code 128 needs light margins on both sides; the downloads include a margin of ten module widths on each side, and you should preserve it in your artwork. Width grows with content — around 11 modules per character plus fixed overhead — so long payloads make wide symbols. If a label keeps failing to scan, the first three suspects are trimmed quiet zones, too-small printing, and low contrast, in that order.

Code 128 and Code 39: the same text, two validators

The nearest alternative for alphanumeric data is Code 39, whose fixed alphabet has 43 characters and no lowercase. The fictional serial-x passes this page's analyzer with its payload untouched; through the Code 39 validator the payload becomes SERIAL-X, with the change disclosed in a note: "Code 39 has no lowercase letters — your input was converted to uppercase." Neither validator guesses — one records a fact, the other changes the text and says so. The guide Code 128 code sets and the Code 39 charset lays both alphabets side by side.

Code 128 FAQ

What characters can I encode?

This tool accepts printable ASCII: letters, digits, space, and punctuation (character codes 32–126). Full Code 128 can also carry ASCII control characters and, via the FNC4 convention, Latin-1 accented text — but FNC4 support is inconsistent across scanners, so this tool rejects those characters with an explanation rather than encoding something that reads differently on different devices.

Does Code 128 have a check digit?

Yes, but not one you type or see. Every Code 128 symbol ends with a mod-103 check character computed over the whole symbol; scanners verify it and it never appears in the human-readable text. The renderer computes it internally — your data is exactly the text you entered, nothing appended.

Why do people say digits are "cheaper" in Code 128?

Code set C encodes two digits per symbol character, so long digit runs take half the width they would as ordinary text. An even-length all-digit input is the most compact case; a good encoder switches to set C automatically for runs of four or more digits.

I pasted a 13-digit product number — why was its check digit not verified?

Because to Code 128 those digits are text: the validated payload carries no check-digit field, and the cited EAN-13 vector 5901234123457 and its corrupted copy 5901234123458 are accepted alike. Paste the number into the EAN-13 generator, where the corrupted copy is refused.

Why did the spaces at the start or end of my text survive?

Because in Code 128 a space is data, so this tool never trims it. The fictional input “ padded ” leaves validation as a payload of 8 characters, and the independent decoder must read back exactly that; a reading of “padded” is a payload mismatch and the barcode is withheld.

Why is there a length cap?

The validator accepts at most 80 characters and refuses one more, naming the cap and its reason. It is this tool's cap, not the symbology's — for longer text, split the data or use a QR code.

Code 128 or a QR code?

Code 128 for laser scanners, conveyor systems, and anywhere one line of text is scanned by hardware; QR codes for phone cameras and richer payloads. If your data is a URL for humans to scan, you want a QR code, not a Code 128.

Is anything I type sent anywhere?

No. Validation, guidance, encoding, and downloads all run locally in your browser.

Verify before production: the generator independently decodes its on-screen SVG and PNG export, but it cannot inspect your printer. Scan the physical sample at final size, or recheck final artwork with the Barcode Verifier. Everything runs locally; see the methodology page. For database merges, industrial printers, or high-volume workflows, use the barcode software decision guide — and if you print on Zebra-family thermal printers, the ZPL printing guide covers the native ZPL download.