# Barcode Generator: Code 128, EAN-13 and UPC-A, PNG and SVG

Page: https://hirantha.me/tools/barcode-generator
Part of: Hirantha Sandaruwan Lakshan free tools (https://hirantha.me/tools)
Updated: 2026-10-15

Make a Code 128, EAN-13 or UPC-A barcode with the check digit worked out for you, then download it as a PNG or SVG. Runs in your browser.

This is a free tool that runs in the browser: open the page to use it. File tools process files on the visitor's own device; files are never uploaded or stored. No account, sign-up, payment or watermark.

Type some text for a Code 128 barcode, or 12 digits for an EAN-13 or 11 for a UPC-A, and the barcode appears at once with its check digit worked out. Choose the module width, height and colours, then download a PNG or an SVG. Mistakes are reported with the exact character that is wrong. Everything is drawn in your browser from the published bar patterns.

Code 128 (ISO/IEC 15417) draws each character as a symbol 11 modules wide, with 3 bars and 3 spaces, and ends with a 13 module stop pattern. This tool uses subset B for letters, digits and punctuation (printable ASCII) and subset C for pairs of digits, which packs digits at twice the density. It looks for the shortest encoding and uses C only where that saves a symbol, which works out as 4 or more digits at the start or the end, 6 or more in the middle, and 2 or at least 4 digits when they are the whole text (not 3). The check symbol is the start value plus each symbol's value times its position (1, 2, 3 and so on), modulo 103. The Wikipedia worked example PJJ123C in code set A sums to 878, and 878 mod 103 = 54. This tool starts that text in subset B (start value 104), so its sum is 879 and its check symbol is 55; both versions decode to PJJ123C. A barcode of n symbols, counting start and check, is 11 x n + 13 modules wide plus its quiet zones.

An EAN-13 is 95 modules: a start guard 101, six left digits, a centre guard 01010, six right digits and an end guard 101, with each digit 7 modules wide. The first digit is not drawn on its own. It chooses which of two patterns (L or G) each of the six left digits uses, which is how 13 digits fit in 12 symbols. The last digit is a check digit: starting from the digit next to it, weight the digits 3, 1, 3, 1 going left, add them up, and the check digit is the amount that rounds the sum up to a multiple of 10. For 400638133393 the sum is 89, so the check digit is 1 and the full number is 4006381333931. A UPC-A is the same bars as the EAN-13 made by putting a 0 in front of its 12 digits.

Quiet zones are blank margins a scanner needs. Code 128 needs at least 10 modules on each side, an EAN-13 11 on the left and 7 on the right (GS1 Sweden size guide), and a UPC-A 9 on each side, so the whole EAN-13 or UPC-A is 113 modules wide. Module width is a whole number of pixels so every edge is sharp, and the PNG and the SVG are drawn from the same list of rectangles, so they always agree. For an EAN-13 on a consumer item GS1 gives 0.264 to 0.660 mm per module with 0.330 mm recommended, so the page shows what your pixel width means on paper at 300 dpi: 4 pixels is 0.339 mm. The same guide pairs the 0.330 mm module with bars 22.85 mm tall, about 69 modules, and the page shows how many modules tall your bars are. The tool warns about low contrast and light bars on a dark background.

A correct pattern does not guarantee a scan. The printer, label stock, size, contrast and scanner all matter, so test every barcode with a real scanner at the size and on the material you will use. Also, a drawing tool cannot give you a product number. Real EAN-13 and UPC-A numbers (GTINs) are built on a GS1 company prefix that you license from GS1 in your country. GS1 Singapore says barcodes from unauthorised sellers are not authentic, not interoperable and would not be recognised globally. Numbers typed here work for tests and internal labels, but they may clash with someone else's product.

The three barcode types compared:
| Type | What it holds | Width | Quiet zone, left / right | Check |
| --- | --- | --- | --- | --- |
| Code 128 | Printable ASCII, up to 80 characters here | 11 modules per symbol + 13 for the stop | 10 / 10 modules | Check symbol, modulo 103 |
| EAN-13 | 12 digits + 1 check digit | 95 modules (113 with quiet zones) | 11 / 7 modules | Check digit, weights 3 and 1 |
| UPC-A | 11 digits + 1 check digit | 95 modules (113 with quiet zones) | 9 / 9 modules | Check digit, weights 3 and 1 |

Q: How is the EAN-13 check digit calculated?
A: Take the first 12 digits. Starting from the one next to the check digit and moving left, multiply them by 3, 1, 3, 1 and so on, then add the results. The check digit is what you add to reach the next multiple of 10. For 400638133393 the sum is 89, so the check digit is 1. Type 12 digits and the tool adds it, or type 13 and it tells you if the last one is wrong.

Q: Do I need to buy barcodes to sell a product?
A: Real product numbers (GTINs) are built on a GS1 company prefix, which you get by joining GS1 in your country. GS1 Singapore describes membership as the way to get a unique company prefix, and warns that barcodes from unauthorised sellers are not authentic. This tool does not allocate numbers. Ask GS1 in your country, and the shop or marketplace you sell through, what they require.

Q: Which type should I use?
A: EAN-13 and UPC-A are the retail product symbols, and they only hold digits. Code 128 holds letters, digits and punctuation and is a common choice for internal labels, shipping and inventory, where you choose your own codes. If a shop or system tells you which one it needs, use that.

Q: Why will my barcode not scan?
A: The usual causes are low contrast between bars and background, light bars on a dark background, bars too small for the printer, missing or cropped quiet zones, a blurry or resized image, and a glossy or curved surface. Use dark bars on a white background, a module of at least 2 or 3 pixels, and print the SVG when the size matters.

Q: What does the invalid character message mean?
A: Code 128 here covers printable ASCII, from space to the tilde. Accented letters, emoji and control characters such as a line break cannot be encoded, and the message names the character, its code and its position. EAN-13 and UPC-A accept digits only; spaces and hyphens are ignored.

Q: Should I download the PNG or the SVG?
A: The PNG is a fixed grid of pixels, good for screens and documents at about its own size. The SVG is a list of rectangles that stays sharp at any size, so use it for large prints and for importing into a design program. Both come from the same bar list and the same module widths.

Q: Can it make GS1-128 or QR codes?
A: No. GS1-128 is Code 128 that begins with an FNC1 symbol followed by a defined data structure, and this tool does not write FNC1, so what you get is plain Code 128. For QR codes use the QR code generator on this site.

Q: Is anything uploaded or stored?
A: No. The barcode is worked out and drawn inside your browser tab and nothing is sent anywhere.

Sources: Code 128 - Wikipedia (symbol table, check symbol, stop pattern, quiet zone) (https://en.wikipedia.org/wiki/Code_128); International Article Number (EAN) - Wikipedia (https://en.wikipedia.org/wiki/International_Article_Number); Universal Product Code - Wikipedia (https://en.wikipedia.org/wiki/Universal_Product_Code); Size guide for barcodes - GS1 Sweden (https://gs1.se/en/guides/how-to-guides/size-guide/); Get a barcode: company prefix and unauthorised sellers - GS1 Singapore (https://gs1.org.sg/faqs/); ZXing barcode reader source: Code128Reader.java (https://github.com/zxing/zxing/blob/master/core/src/main/java/com/google/zxing/oned/Code128Reader.java)

Related tools:

- [QR code generator](https://hirantha.me/tools/qr.md): Turn a link, note, or Wi-Fi password into a QR code you can download.
- [Colour contrast checker](https://hirantha.me/tools/color-contrast-checker.md): Check the WCAG contrast ratio of a text and background colour, see AA and AAA pass or fail for normal and large text, and get the nearest colour that passes.
- [UUID generator](https://hirantha.me/tools/uuid-generator.md): Generate random version 4 UUIDs, one at a time or in bulk.
