Barcode Generator
Code 128 subset B: any character from ASCII 32 to 126.
The barcode generator produces Code 128 subset B barcodes as scalable SVG. Code 128 is the symbology used for shipping labels, asset tags and internal inventory codes, and subset B encodes the whole printable ASCII range, every character on a standard keyboard.
How it works
Each character maps to a pattern of six bar and space widths. The symbol is a start pattern, the encoded data, a checksum character, then a stop pattern.
checksum = (104 + sum of value(i) x (i + 1)) mod 103
- 104
- the start value for subset B
- value(i)
- the character value, which is its ASCII code minus 32
- i + 1
- the position weight, counting from 1
The generated SVG includes a 10-module quiet zone on each side. Scanners need that clear margin to find the symbol edges, and cropping it is the most common reason a printed barcode will not read.
Examples
An alphanumeric asset tag
Value
CADMEO-12345
Bar height
80px
Result
A Code 128 B symbol with a computed checksum, human-readable text below the bars
Letters, digits and a hyphen are all within subset B, so the value encodes directly with no character-set switching.
A value with an unsupported character
Value
CAFÉ-01
Result
Rejected: contains characters Code 128 B cannot encode
É is outside ASCII 32 to 126. Rather than silently dropping it and producing a barcode that scans as CAF-01, the tool refuses to encode.
Frequently asked questions
Which characters can Code 128 subset B encode?
ASCII 32 to 126, space, digits, uppercase and lowercase letters, and standard punctuation. Accented letters, emoji and control characters are outside the set. Subsets A and C cover control characters and dense numeric pairs respectively, and this tool implements B only.
Why does the barcode include a checksum character?
Because Code 128 requires one. It is a weighted modulo-103 sum of the encoded values, and scanners verify it before reporting a read. It is what stops a partially damaged symbol being read as a different valid code.
Why is the SVG wider than the bars?
That is the quiet zone, 10 modules of blank space each side. Scanners use it to locate the symbol edges, and cropping it is the single most common reason a printed barcode fails to scan.
Can I use this for retail products?
Not for retail scanning at a till, which needs a UPC or EAN barcode tied to a registered GS1 company prefix. Code 128 is for internal use (shipping labels, asset tags, warehouse locations) where you control both the code and the scanner.