What you need to know before generating a barcode

A barcode is a machine-readable image that encodes product information — usually a unique identifier number — into a format that scanners can read. To create one, you need three things: a barcode number (often called a SKU or UPC), barcode generation software or a library, and a decision about which barcode format fits your product and sales channel.

The format matters because different retailers and industries use different standards. A grocery store expects a UPC-A barcode (12 digits). An Amazon seller might use an ASIN barcode. A warehouse might use Code128. The format you choose determines what software you can use and how the barcode will look.

You do not need to buy a barcode number if you are selling only through your own website or a platform like Etsy — you can generate one yourself. If you are selling through major retailers like Target or Walmart, you will need to purchase a barcode number from GS1, the organization that manages barcode standards in your country.

Key Takeaways

  • Different sales channels require different barcode formats: UPC-A for retail stores, Code128 for warehouses, and custom formats for online platforms.
  • You can generate a barcode number yourself for free if you sell only through your own channels, but major retailers require a purchased GS1 barcode.
  • Barcode generation libraries like python-barcode, Barcode4J, and online generators create the image file from your number in minutes.
  • Test your barcode with a scanner before printing or uploading to catch errors that will cause scanning failures at checkout.
  • Store your barcode image as a high-resolution file (at least 300 DPI for print) to avoid blurry or unreadable results.

Choosing the right barcode format for your product

The barcode format you choose depends on where you plan to sell. UPC-A is the standard for retail stores in North America — it encodes 12 digits and produces the familiar black-and-white striped barcode you see on grocery items. EAN-13 is the European equivalent and encodes 13 digits. Code128 is more flexible and used in warehouses and logistics because it can encode letters, numbers, and special characters.

If you are selling through Amazon, use the ASIN (Amazon Standard Identification Number) that Amazon assigns to your product — you do not generate this yourself. If you are selling through Shopify, WooCommerce, or your own website, you can use any format, though Code128 is common because it is compact and reliable. Etsy sellers often use Code128 or EAN-13.

Check with your retailer or sales platform first. Many have documentation that specifies which format they accept. If you are unsure, Code128 is the safest choice because it works across most systems and can encode more information than UPC-A.

Obtaining or generating a barcode number

If you are selling through your own website or a platform that does not require a specific barcode number, you can generate one yourself. For Code128 barcodes, you can use any number you want — there is no central registry. For UPC-A or EAN-13, you have two options: purchase a legitimate barcode from GS1, or generate a number yourself if you are not selling through major retailers.

GS1 sells barcode numbers in batches. In the United States, a single UPC-A barcode costs around $30 to $250 depending on how many you buy at once and your company size. In the UK and Europe, EAN-13 barcodes are available through GS1 UK or your country's equivalent. The cost and process vary by country. If you only need one or two barcodes and are not selling in physical retail stores, the cost may not be worth it.

If you generate your own number, make sure it is unique — do not reuse a number across different products. For testing or internal use, many generators accept placeholder numbers like "123456789012" for UPC-A. Document which number you assigned to which product so you can track inventory correctly.

Using barcode generation software and libraries

Several tools can turn your barcode number into an image file. The tool you choose depends on whether you want a one-time solution or something you can integrate into your workflow.

Online generators are the fastest option if you only need a few barcodes. Websites like Barcode Lookup, TEC-IT, and Zint Online Barcode Generator let you paste your number, select a format, and download the image in seconds. No installation required. The downside is that you have to generate each barcode one at a time, and some free generators add watermarks or limit file formats.

Python libraries like python-barcode work well if you are comfortable writing code or want to automate barcode generation for hundreds of products. Install the library with pip install python-barcode, then write a short script that reads product numbers from a spreadsheet and generates an image for each one. The library supports UPC-A, EAN-13, Code128, and others.

Java libraries like Barcode4J are similar to python-barcode but run in Java environments. They are often used in enterprise systems where barcode generation is part of a larger inventory or point-of-sale system.

Desktop software like Bartender or Labeljoy gives you a graphical interface and more control over barcode appearance, size, and placement on labels. These tools cost money but are useful if you are printing thousands of barcodes and need consistent formatting.

Generating and exporting your barcode image

Once you have chosen your tool and have your barcode number, the generation process is straightforward. If you are using an online generator, paste your number, select the format (UPC-A, Code128, etc.), and click Generate. Most will show you a preview and let you download as PNG, SVG, or PDF.

If you are using a library, the process depends on the language. Here is a simple python-barcode example:

from barcode import EAN13 from barcode.writer import ImageWriter ean = EAN13('5901234123457', writer=ImageWriter()) ean.save('product_barcode')

This creates a file called product_barcode.png with your barcode image. You can then open it in an image editor, resize it, or place it on a product label.

For print use, export at 300 DPI (dots per inch) or higher so the barcode stays sharp and scannable. For digital use (like on a website or in an app), 72 DPI is fine. If your generator does not offer DPI settings, use PNG or PDF format — both preserve quality better than JPEG when you resize them later.

Testing your barcode before use

Before you print or upload your barcode, test it with a scanner. Barcode scanners are inexpensive — a basic USB barcode scanner costs $20 to $50 and plugs into any computer. If you do not have a physical scanner, some smartphone apps can read barcodes using the phone's camera.

Scan your generated barcode image on your screen or print a test copy and scan it. The scanner should output the exact number you encoded. If it outputs a different number or nothing at all, the barcode is corrupted or the format is wrong. Common problems include: the barcode image is too small (minimum size varies by format but is usually around 0.5 inches wide), the contrast is too low (black bars must be truly black, white spaces truly white), or the format does not match what your scanner expects.

If a test scan fails, regenerate the barcode with a different tool or check that your number is valid for the format you chose. For example, UPC-A requires exactly 12 digits — if you provide 11 or 13, the generator may reject it or add a check digit automatically, which changes the number.

Storing and managing your barcode files

Once your barcode is working, store the image file in a consistent location with a clear naming system. Name files by product number or SKU so you can find the right barcode quickly: product_SKU_5901234.png or UPC_012345678901.png. Keep both the original high-resolution version (for printing) and a web-optimized version (for websites or apps).

If you are generating barcodes for many products, create a spreadsheet that maps each product to its barcode number and file location. This prevents you from accidentally using the same barcode twice or losing track of which barcode belongs to which product. Include columns for product name, barcode number, format, date generated, and file path.

Back up your barcode files and the spreadsheet. If you lose the barcode image, you can regenerate it from the number, but it is faster to have the original on hand. If you lose the mapping spreadsheet, you may not remember which number you assigned to which product.

Frequently Asked Questions

Can I use the same barcode for multiple products?

No. Each barcode number should represent one unique product. If you use the same barcode on two different items, inventory systems will not be able to tell them apart, and you will lose track of stock. The only exception is if you are selling the exact same product under different names or in different packages — in that case, the barcode should still be the same because it is the same product.

What happens if I print a barcode that is too small?

Scanners may not be able to read it. The minimum size depends on the barcode format — UPC-A should be at least 0.5 inches wide, Code128 can be smaller. If your barcode is too small, the scanner's laser cannot distinguish the individual bars and spaces, and the scan will fail. Print a test copy and scan it before printing your full batch.

Do I need a barcode if I sell only online?

Not necessarily. If you sell through your own website, you can use any identifier you want — a product ID, SKU, or custom number. Barcodes are most useful when physical items move through multiple systems (warehouse, store shelf, checkout) that all need to read the same code. Online-only sellers often skip barcodes unless they also use them for internal inventory tracking.

What is the difference between a barcode and a QR code?

A barcode (like UPC-A or Code128) encodes information in one dimension — the width and spacing of vertical bars. A QR code encodes information in two dimensions — a grid of black and white squares — so it can hold much more data. QR codes are useful for linking to websites or storing detailed product information, while barcodes are faster to scan at checkout and work with older scanners.

Can I edit a barcode image after it is generated?

You can resize or reposition it in an image editor, but do not change the bars or spaces themselves. Editing the actual barcode pattern will make it unreadable. If you need to change the number it represents, regenerate the barcode from scratch rather than trying to edit the existing image.