Developer Tools Barcode Utilities Tutorial

Free Online Barcode Generator — Code 128, EAN-13, UPC & More

· 9 min read

Barcodes are the invisible infrastructure of modern commerce. Every product on a supermarket shelf, every package in a fulfillment center, every medication vial in a pharmacy, and every library book carries a barcode that encodes identity into machine-readable form. Despite their ubiquity, creating a barcode often means wrestling with expensive label software, bloated desktop applications, or sketchy ad-filled websites that want your email address before generating a single image.

Our free online barcode generator changes that. It supports eight major barcode formats, lets you customize dimensions and colors, exports to PNG or SVG, and runs entirely in your browser. No signup. No server upload. No data leaves your device. This guide explains what barcodes are, how they work, which format to choose for your use case, and how to generate professional barcodes in seconds.

What Is a Barcode?

A barcode is a machine-readable representation of data encoded as a pattern of parallel lines, spaces, or geometric shapes. The most familiar type — the one-dimensional barcode made of vertical black bars and white spaces — stores data in the relative widths of those elements. A barcode scanner shines a laser or LED across the pattern, measures the reflected light intensity, and decodes the widths back into the original characters.

The concept dates back to 1948 when Norman Joseph Woodland and Bernard Silver, graduate students at Drexel Institute of Technology, patented a system for automatically reading product information. Inspired by Morse code, Woodland drew dots and dashes in sand on a beach, then extended them into lines. The first successful commercial application was in 1974 when a pack of Wrigley's chewing gum became the first product scanned at a supermarket checkout in Troy, Ohio.

Today, barcodes are not just for retail. They track blood samples in hospitals, manage inventory in warehouses, identify assets in enterprises, control access at events, and encode test data in software development. The GS1 organization estimates that over 5 billion barcodes are scanned every day worldwide.

How Barcodes Work: The Physics

When a scanner illuminates a barcode, dark bars absorb light while white spaces reflect it. A photodiode in the scanner measures the intensity of reflected light over time as the beam sweeps across the code. Because the scanner moves at a relatively constant speed (or the barcode moves past a fixed scanner), the time-domain signal maps directly to the spatial pattern of bars and spaces.

The scanner converts this analog light signal into a digital waveform: low voltage for dark bars, high voltage for light spaces. A decoder then measures the widths of each element and matches them against the encoding rules of the specific barcode symbology. Each symbology defines how characters map to bar-space patterns, what start and stop patterns identify the barcode boundaries, and how checksums verify data integrity.

One-Dimensional vs. Two-Dimensional

This article focuses on one-dimensional (1D) linear barcodes — the classic bar-and-space patterns. These encode data in one dimension (horizontally) and require a laser sweep to read. Two-dimensional codes like QR codes and Data Matrix encode data in both dimensions and can be read by cameras. If you need 2D codes, our QR Code Generator handles those separately.

Barcode Format Types: A Complete Guide

Not all barcodes are interchangeable. Each symbology was designed for specific industries, character sets, and data densities. Choosing the wrong format means your barcode will not scan, or worse, it will scan incorrectly. Here is what our generator supports and when to use each.

Code 128

Best for: General-purpose encoding, logistics, supply chain, shipping labels

Code 128 is the most versatile linear barcode symbology. It can encode all 128 ASCII characters — uppercase letters, lowercase letters, numbers, punctuation, and control characters — making it the go-to choice for applications that need more than just digits. It achieves high density by using three different character sets (A, B, and C) and switching between them within a single barcode to minimize length.

Character Set A covers ASCII control characters and uppercase letters. Character Set B covers uppercase, lowercase, and symbols. Character Set C encodes pairs of digits as single symbols, effectively doubling numeric density. A smart encoder analyzes the input and selects the optimal character set sequence to produce the shortest possible barcode.

Code 128 requires a modulo-103 checksum calculated over all symbol values including the start character. This checksum catches most single-symbol errors and many transposition errors. The barcode also includes start and stop patterns and a termination bar.

Real-world applications include SSCC shipping labels, blood bag identification, packaging serial numbers, and any scenario where you need alphanumeric data in a compact linear format.

EAN-13

Best for: Retail product identification, especially outside North America

EAN-13 (European Article Number, 13 digits) is the international retail standard. If you buy a product in Europe, Asia, or South America, it almost certainly carries an EAN-13 barcode. The 13 digits encode a country prefix (2-3 digits), manufacturer code (4-5 digits), product code (4-5 digits), and a modulo-10 check digit.

The structure is: GS1 Prefix + Manufacturer + Product + Check Digit. For example, a barcode starting with 690-699 was issued in China. One starting with 50 was issued in the UK. The GS1 organization manages prefix allocation globally to prevent collisions.

EAN-13 can only encode numeric data. It uses a clever encoding where the left half of digits uses odd or even parity patterns that also encode the first digit (the GS1 prefix), allowing 13 digits to fit in the space of 12. The right half always uses standard patterns. This means an EAN-13 scanner can derive the first digit from the left-half parity alone.

If you are selling products through retail channels, you need legitimate GS1-registered EAN-13 numbers. Our generator can create the barcode image, but the number itself must come from GS1 or an authorized reseller.

EAN-8

Best for: Small products where EAN-13 does not fit

EAN-8 is a compressed version of EAN-13 with 8 digits: a GS1 prefix, product code, and check digit. It exists purely for physical space constraints — think of small candy bars, lipstick tubes, or individual teabags where a full EAN-13 would wrap around the package.

Because the number space is smaller, GS1 tightly controls EAN-8 allocation. You cannot simply truncate an EAN-13. The encoding structure is similar but without the parity-derived first digit trick; all 8 digits are explicitly encoded.

UPC-A

Best for: North American retail products

UPC-A (Universal Product Code) is the North American equivalent of EAN-13. It encodes 12 numeric digits: a number system digit, manufacturer code (5 digits), product code (5 digits), and a modulo-10 check digit. The number system digit indicates the product category: 0, 1, 6, 7, and 8 for regular items, 2 for variable-weight items, 3 for pharmaceuticals, 4 for in-store use, and 5 for coupons.

UPC-A is technically a subset of EAN-13. If you prepend a zero to a UPC-A code, it becomes a valid EAN-13. This is why most modern scanners can read both formats interchangeably. However, if you are selling in North America, you should use UPC-A format for compliance.

Like EAN-13, legitimate UPC codes must be purchased from GS1 US or an authorized source. Our tool generates the barcode image from whatever number you provide.

Code 39

Best for: Industrial labeling, asset tracking, military applications, low-density alphanumeric

Code 39, also known as Alpha39 or Code 3 of 9, was one of the first alphanumeric barcode symbologies and remains widely used in industrial and military contexts. It encodes 43 characters: uppercase A-Z, digits 0-9, and seven special characters (- . $ / + % space).

Code 39 is self-checking — most single-character errors are detectable without an explicit checksum, though an optional modulo-43 checksum can be appended for additional security. The symbology uses a simple pattern: each character is nine elements wide, with exactly three of those elements being wide (hence "3 of 9") and the rest narrow. This fixed structure makes it easy to decode but relatively low-density compared to Code 128.

The low density means Code 39 barcodes are longer for the same data. This is acceptable for asset tags, warehouse shelf labels, and military shipping labels where space is not the primary constraint. It is also one of the most reliably scannable formats because the wide/narrow ratio tolerances are generous.

ITF-14

Best for: Shipping cartons, case packs, pallet-level tracking

ITF-14 (Interleaved 2 of 5 with 14 digits) encodes a Global Trade Item Number (GTIN) at the packaging level. While EAN-13 and UPC-A identify individual consumer units, ITF-14 identifies cases, cartons, and pallets containing those units. The 14 digits include an indicator digit (1-8 for packaging levels, 9 for variable quantity), the 12-digit item reference, and a check digit.

ITF-14 uses Interleaved 2 of 5 symbology, where pairs of digits are encoded together — one digit in the bars, the next in the spaces. This interleaving achieves high density but requires an even number of digits (hence the padding to 14). The format always includes a bearer bar (a box around the barcode) to prevent partial scans from being misread.

If you manage a supply chain, ITF-14 is how your warehouse knows whether a pallet contains 24 units or 48, and how your retailer knows they received the correct case quantity.

Codabar

Best for: Libraries, blood banks, photo labs, overnight delivery

Codabar was developed in 1972 and became popular in specific niche industries. It encodes digits 0-9 and six symbols (- $ : / . +). Unlike most symbologies, Codabar uses discrete characters — each character is self-contained and does not interleave with neighbors — making it easy to print on low-resolution dot-matrix printers and typewriters.

The start and stop characters (A, B, C, or D) can be combined to encode additional information. For example, libraries use the start/stop characters to indicate item type: A for regular books, B for reference materials, C for periodicals. Blood banks historically used Codabar for specimen identification because the format was readable even on blood-soaked labels.

Codabar is gradually being replaced by Code 128 in most applications, but it remains the standard in libraries and some legacy medical systems.

Pharmacode

Best for: Pharmaceutical packaging control

Pharmacode, also known as Pharmaceutical Binary Code, is a specialized format used exclusively in the pharmaceutical industry to control packaging lines. It encodes a single numeric value from 3 to 131070 using a binary pattern of wide and narrow bars.

Unlike other barcodes, Pharmacode is designed to be readable in either direction and even upside-down. This is critical on high-speed packaging lines where bottles or blister packs may rotate before reaching the scanner. The value typically encodes the product ID and packaging configuration, telling the line which leaflet to insert, which label to apply, and which carton to use.

Pharmacode has no checksum. Error detection relies on the limited valid range and the packaging line's validation systems. It is not a general-purpose barcode — you will only encounter it if you work in pharmaceutical manufacturing.

How Barcodes Encode Data: The Technical Layer

Understanding the encoding process helps you diagnose scan failures, choose appropriate formats, and design barcodes that work in production environments. Here is what happens when you type a string into our generator.

Character Mapping

Each symbology maintains a lookup table that maps valid characters to bar-space patterns. In Code 128, each character maps to an 11-module pattern (6 bars and 5 spaces, or vice versa) with three possible bar widths. In EAN-13, each digit maps to a 7-module pattern with two bar widths. The mapping is deterministic — the same character always produces the same pattern.

Start and Stop Patterns

Every barcode begins with a start pattern and ends with a stop pattern. These serve multiple purposes: they tell the scanner which symbology is being used, they establish the timing reference for measuring element widths, and they define the barcode boundaries. Without these patterns, a scanner cannot distinguish barcode data from background noise.

Checksum Calculation

Most barcode symbologies include a checksum to catch scanning errors. The algorithm varies by format:

  • EAN-13 / UPC-A: Modulo-10. Starting from the right, sum odd-position digits multiplied by 3 and even-position digits. The check digit is the number that makes the total a multiple of 10
  • Code 128: Modulo-103. Sum each symbol value (including the start character) multiplied by its position weight, then take modulo 103
  • Code 39: Optional modulo-43. Sum character values and take modulo 43
  • ITF-14: Modulo-10, similar to EAN-13 but applied to 14 digits

Our generator automatically calculates and appends the correct checksum. You do not need to compute it manually.

Quiet Zones

Every barcode requires a quiet zone — a margin of blank space on both sides. The quiet zone must be at least 10 times the width of the narrowest element (the X-dimension). Without adequate quiet zones, the scanner may miss the start pattern or misread adjacent graphics as barcode data. This is why you should never place barcodes flush against text, borders, or other barcodes.

Rendering

The final step converts the module patterns into actual graphics. Each module becomes a rectangle of a specific width. Bars are filled with the foreground color; spaces are filled with the background color. The generator renders to both canvas (for PNG export) and SVG (for vector output), applying your chosen dimensions and colors.

Using Our Online Barcode Generator

Our free barcode generator online is designed for speed and simplicity while supporting professional requirements. Here is how to create barcodes in seconds.

Step-by-Step Guide

  1. Open the tool: Navigate to Barcode Generator
  2. Select a format: Choose from Code 128, EAN-13, EAN-8, UPC, Code 39, ITF-14, Codabar, or Pharmacode
  3. Enter your data: Type the value you want to encode. The generator validates input against the selected format's character set and length rules in real time
  4. Customize appearance: Adjust the barcode width and height, choose foreground and background colors, and toggle human-readable text display
  5. Preview: The barcode renders instantly as you type and adjust settings
  6. Download: Click PNG for raster output or SVG for vector output. Both download immediately
  7. Test scan: Use any barcode scanner app on your phone to verify the barcode decodes correctly before printing

Input Validation

Each format enforces its own rules:

  • EAN-13: Exactly 13 digits, or 12 digits with automatic check digit calculation
  • EAN-8: Exactly 8 digits, or 7 digits with automatic check digit calculation
  • UPC-A: Exactly 12 digits, or 11 digits with automatic check digit calculation
  • Code 39: Uppercase letters, digits, and - . $ / + % space only
  • ITF-14: Exactly 14 digits, or 13 digits with automatic check digit calculation
  • Codabar: Digits and - $ : / . + only, with A-D start/stop characters
  • Pharmacode: Numeric value between 3 and 131070
  • Code 128: Any ASCII character

If your input violates a format's rules, the generator shows a clear error message immediately.

Customization Options

  • Width and height: Control the physical dimensions of the output image. Larger barcodes scan more easily from a distance
  • Foreground color: Default is black, but you can choose any color. High contrast is essential for reliable scanning
  • Background color: Default is white. Avoid dark backgrounds that reduce contrast
  • Display text: Toggle the human-readable text below the barcode. Essential for manual verification, optional for automated-only scanning

Download Formats

  • PNG: Raster format with transparent background. Best for web use, documents, and quick sharing
  • SVG: Vector format that scales infinitely without quality loss. Essential for print design, large-format labels, and professional graphics workflows

100% Client-Side

All barcode generation happens in your browser using the JsBarcode library. No data is transmitted to any server. Your product codes, shipping labels, and inventory identifiers never leave your device. The tool works offline after the initial page load, making it safe for sensitive business data and usable in restricted environments.

Barcode Design Best Practices

A barcode that looks correct to the human eye can still fail to scan. These best practices separate working barcodes from frustrating ones.

Maintain High Contrast

Scanners detect barcodes by measuring reflected light intensity. The greater the difference between bar and space reflectivity, the more reliable the scan. Black bars on white backgrounds provide the highest contrast and the best scan rates. If you use colors, ensure the foreground is dark and the background is light. Never use similar colors (e.g., dark blue on black) or gradients. Red bars are particularly problematic because many scanners use red light, which red bars reflect rather than absorb.

Respect Quiet Zones

The quiet zone is not decorative — it is part of the barcode specification. For most formats, the quiet zone must be at least 10 times the X-dimension (width of the narrowest element) on both sides. When placing barcodes on labels, packaging, or documents, ensure no text, graphics, or borders intrude into this margin. A common failure mode is placing a barcode too close to a fold, edge, or another barcode.

Choose the Right Size

Barcode size affects scan reliability. Smaller barcodes have narrower elements that are harder for scanners to resolve. As a rule of thumb:

  • Retail checkout: EAN-13 should be at least 80% of the nominal size (26.73 mm × 18.28 mm) and no more than 200%
  • Warehouse scanning: Larger is better. Case labels should be at least 50 mm wide
  • Small items: EAN-8 or reduced-size EAN-13 for items under 50 mm diameter
  • Distance scanning: Increase size proportionally to scanning distance. A barcode scanned from 2 meters needs to be roughly twice as large as one scanned from 1 meter

Use Vector Formats for Print

Always download barcodes as SVG for print applications. Raster formats like PNG lose quality when resized, and a blurry barcode is an unscannable barcode. SVG files contain precise mathematical descriptions of each bar and space, ensuring perfect reproduction at any size on any printer.

Test Before Mass Production

Always test barcodes with the actual scanners used in your production environment. A barcode that scans perfectly on your phone may fail on an industrial laser scanner, or vice versa. Test at multiple angles, distances, and lighting conditions. Print a sample label and verify it after your actual printing process — thermal transfer, inkjet, and laser printers each produce different edge qualities that affect scan performance.

Avoid Common Layout Mistakes

  • Do not stretch or compress barcodes non-uniformly. Aspect ratio must be preserved
  • Do not rotate 1D barcodes. They must be readable by a horizontal laser sweep
  • Do not place barcodes over seams, folds, or curved surfaces if avoidable
  • Do not use glossy or reflective label materials that create specular highlights
  • Do not truncate or crop the barcode image

Barcodes in Software Development

Developers encounter barcodes in more contexts than they expect. Here is how our generator fits into development workflows.

Generating Test Data

When building inventory systems, POS software, or warehouse management applications, you need realistic barcode data for testing. Instead of manually creating dummy codes, use our generator to produce valid EAN-13, UPC-A, and Code 128 barcodes with correct checksums. Test your scanner integration, database lookups, and validation logic with real barcode images rather than plain text strings.

Mocking External Systems

Integration tests for e-commerce platforms often require simulating supplier shipments with SSCC labels, or simulating retail scanning at checkout. Generate ITF-14 case codes and Code 128 serial numbers to create realistic test fixtures. Because the generator runs client-side, you can even automate it in headless browser tests using tools like Playwright or Puppeteer.

Prototyping Hardware Interfaces

When building custom hardware with barcode scanner modules (e.g., Raspberry Pi with USB scanner, Arduino with serial scanner), you need known-good barcodes to verify the hardware interface and parsing logic. Print test sheets from our generator and scan them against your firmware.

Label Generation in Applications

If you are building an application that needs to generate barcodes dynamically, studying our implementation helps you understand which libraries to use (JsBarcode for browser-based generation, python-barcode for server-side, ZXing for Android) and how to configure them for different symbologies.

Common Use Cases

  • Retail product labels: Generate EAN-13 or UPC-A barcodes for products sold through retail channels
  • Warehouse inventory: Create Code 128 barcodes for SKU numbers, bin locations, and serial numbers
  • Shipping and logistics: Generate SSCC-18 (Code 128-based) and ITF-14 codes for cartons and pallets
  • Asset tracking: Label office equipment, IT assets, and tools with Code 39 or Code 128 identifiers
  • Library management: Print Codabar barcodes for book and patron identification
  • Healthcare specimens: Generate Code 128 barcodes for blood samples, patient wristbands, and medication tracking
  • Event access control: Create Code 128 barcodes for ticket validation and attendee tracking
  • Manufacturing: Generate Pharmacode labels for pharmaceutical packaging lines
  • Testing and QA: Produce valid barcode images for software testing and hardware validation
  • Small business operations: Print barcode labels for homemade products, craft inventory, and local retail

Frequently Asked Questions

Is this barcode generator free?

Yes, completely free. No signup, no usage limits, no ads. Generate as many barcodes as you need.

Does it upload my data to a server?

No. All barcode generation happens 100% client-side in your browser. Your product codes, inventory numbers, and business data never leave your device.

Can I use the barcodes commercially?

Yes, the generated barcode images are yours to use. However, if you need barcodes for retail sale (EAN-13 or UPC-A), you must obtain legitimate number assignments from GS1 or an authorized reseller. Our tool creates the image, but we do not provide GS1-registered numbers.

What is the best barcode format for general use?

Code 128 is the best general-purpose choice. It supports full ASCII, achieves high density, and is readable by virtually all modern scanners. Use EAN-13 or UPC-A only for retail products that require GS1 compliance.

Can I customize colors?

Yes. Choose any foreground and background color using the color pickers. For best scan reliability, maintain high contrast — dark foreground on light background.

Does it calculate check digits automatically?

Yes. For EAN-13, EAN-8, UPC-A, and ITF-14, you can enter the data without the check digit and the generator will calculate and append it automatically. You can also enter the full code including the check digit if you prefer.

Can I download as SVG?

Yes. Both PNG and SVG export are supported. SVG is strongly recommended for any print application.

Why does my barcode not scan?

Common causes: low contrast colors, missing quiet zones, too small size, poor print quality, damage or smudging, scanning at extreme angles, or using a format your scanner does not support. Try black on white, increase the size, and ensure adequate margins.

What is the difference between Code 128 and Code 39?

Code 128 supports lowercase letters and full ASCII, achieves higher density, and uses a more complex checksum. Code 39 supports only uppercase, digits, and limited symbols, produces longer barcodes, but is more forgiving of print quality and scanner resolution. Use Code 128 unless you specifically need Code 39 compatibility.

Does it work on mobile?

Yes. The tool is fully responsive and works on any device with a modern web browser. You can generate barcodes on your phone and save them directly to your camera roll.

Can I generate multiple barcodes at once?

The current interface generates one barcode at a time. For bulk generation, you can automate the underlying JsBarcode library in a script, or generate barcodes one by one and download each.

What is the maximum length for Code 128?

Code 128 has no fixed maximum length, but practical limits apply. Most scanners handle up to 48 characters reliably. Longer codes become physically wide and may exceed scanner field-of-view or label space.

Try It Now

No signup, no upload, no server calls. Open Barcode Generator, select your format, enter your data, customize the appearance, and download your barcode instantly.

Looking for more free developer tools? Browse our full tools directory — including QR Code Generator, Unit Converter, Color Converter, and CSV to JSON Converter.

Found this useful? Check out our free developer tools or browse more articles.