Barcodes are the invisible infrastructure of commerce and logistics. Every package passing through a warehouse, every product on a retail shelf, every piece of equipment in an asset inventory—all identified by patterns of black and white lines that machines read instantly.
For developers building inventory systems, shipping workflows, or asset trackers, barcode generation is a fundamental capability. When products enter your system, they need barcodes. When packages ship, tracking numbers need to become scannable labels. When equipment gets tagged, asset IDs need physical representation.
How Barcodes Work
A barcode encodes data as a pattern of bars and spaces of varying widths. Scanners read these patterns by measuring the reflectivity of each segment—dark bars absorb light, white spaces reflect it. The sequence of measurements translates back into the original data.
Different barcode symbologies (formats) use different encoding schemes. Some encode only numbers. Some encode letters and numbers. Some can represent any data including binary. The choice of symbology depends on what you're encoding and where the barcode will be scanned.
The physical appearance matters too. Barcodes need sufficient contrast between bars and background. They need minimum sizing to be scannable at practical distances. They need quiet zones (blank space) around them so scanners know where the barcode begins and ends.
Understanding these fundamentals helps you generate barcodes that actually work in real-world scanning environments.
Code 128: The Modern Standard
Code 128 is the most widely used barcode symbology for logistics and inventory. It's compact, efficient, and supports the full ASCII character set—letters, numbers, and symbols.
The compactness matters. Code 128 encodes more data per inch than older symbologies. A Code 128 barcode containing "SKU-12345678" is physically shorter than the same data in Code 39. Shorter barcodes fit on smaller labels and scan more reliably at angles.
Code 128 automatically switches between encoding modes to optimize density. Sequences of numbers encode more compactly than sequences of letters. The symbology handles this internally—you just provide the data.
For most applications—product labels, shipping labels, inventory tags—Code 128 is the right choice. It's supported by virtually every scanner and works across all industries.
Code 39: The Legacy Workhorse
Code 39 is older and less efficient than Code 128, but it remains common in certain industries. The US Department of Defense uses Code 39 for military asset tracking. Many automotive manufacturers specify Code 39 in their supply chain requirements.
Code 39 encodes uppercase letters, numbers, and a few special characters. It's self-checking, meaning a single misread bar won't produce valid-looking garbage—it will produce an invalid barcode that the scanner rejects.
The trade-off is density. Code 39 barcodes are physically wider than Code 128 for the same data. A 15-character asset ID in Code 39 might be twice as wide as Code 128.
Use Code 39 when external requirements mandate it. For new systems without legacy constraints, Code 128 is generally better.
Designing Barcode Labels
A barcode by itself is just a pattern. Useful labels combine the barcode with human-readable information.
Human-readable data appears below the barcode. This is the same data encoded in the barcode, printed as text. When scanners fail, humans can read the number and enter it manually. Include this on every label.
Contextual information surrounds the barcode. For a product label, this might include the product name, price, or size. For a shipping label, the recipient address and service level. The barcode identifies; the context explains.
Layout matters for scanning. Barcodes need quiet zones—blank space on either side. They need minimum height for reliable scanning. They need contrast with the background. A barcode crammed into a corner with no margins will cause scanning failures.
Print quality affects reliability. Thermal printers produce excellent barcodes. Inkjet printers work but require good paper. Laser printers sometimes produce barcodes with insufficient contrast. Test your actual printing process with actual scanners before deploying.
Inventory and SKU Labels
Inventory management systems typically assign SKU (Stock Keeping Unit) codes to products. These SKUs become barcodes on product labels.
SKU formats vary by organization. Some use sequential numbers. Some encode product attributes into the SKU structure. Some combine vendor codes with internal identifiers. Whatever your SKU format, it becomes barcode content.
The workflow looks like this: A new product enters inventory. The system assigns a SKU. The system generates a barcode encoding that SKU. The barcode prints on a label. The label attaches to the product or its storage location.
From then on, workers scan to interact with inventory. Scanning a product during receiving updates quantity counts. Scanning during picking confirms the right product. Scanning during shipping records what went out. The barcode is the link between physical items and database records.
Shipping and Tracking Labels
Shipping labels present specific requirements. They're affixed to packages that travel through rough environments. They're scanned by many different parties—your warehouse, the carrier, intermediate hubs, the recipient.
Tracking numbers encode into barcodes on shipping labels. These numbers are typically assigned by carriers, though some shippers generate their own for internal tracking before carrier handoff.
The label usually includes multiple barcodes. A large barcode for the tracking number. Smaller barcodes for routing information. These redundant encodings help when packages are damaged or when different scanners have different capabilities.
Label placement affects scanning. Labels should be on flat surfaces, not wrapped around corners. They should be visible without opening or manipulating the package. Standard placement (top of package for flat items, side for boxes) helps automated scanning systems.
Asset Tracking Tags
Organizations track equipment, tools, vehicles, and other assets with barcode tags. Unlike inventory that flows in and out, assets typically stay within the organization but move between locations and users.
Asset IDs often encode more than just a number. They might include category codes, location codes, or department identifiers. An asset ID like "IT-LAP-2024-0047" encodes the department (IT), asset type (laptop), year, and sequence. This structure helps humans understand the ID even without looking it up.
Asset tags need durability. Equipment lasts years. Tags must survive handling, cleaning, and environmental conditions. Metal asset tags with engraved barcodes work for harsh environments. Laminated labels work for office equipment. Matching tag durability to asset lifecycle prevents premature tag failure.
Periodic scanning maintains asset databases. Annual inventories scan all equipment. Check-out processes scan before equipment leaves. Check-in processes scan on return. Each scan updates location and status.
Batch Generation
Many workflows need many barcodes at once. A new shipment of products needs labels for every item. A warehouse reorganization needs location labels for every bin. An IT refresh needs asset tags for every device.
Batch generation creates multiple barcodes efficiently. Rather than generating one at a time, generate all needed barcodes in a single operation. This is faster and ensures consistency—all labels from the same batch look identical.
Batch output might be individual images or a print-ready document. Individual images work when labels print separately or integrate into other documents. Print-ready documents work for label sheets that print all at once.
Label sheets follow standard formats. Avery 5160 provides 30 labels per letter-sized page. Avery 5163 provides 10 larger labels. Matching your output to your label stock saves time and materials.
Integration Example
Generating a barcode through an API is straightforward:
const response = await fetch('https://api.apiverve.com/v1/barcodegenerator', {
method: 'POST',
headers: {
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
data: 'SKU-12345678',
type: 'code128',
displayValue: true
})
});
const { data } = await response.json();
// data.downloadURL contains the barcode image
The displayValue option prints the encoded data below the barcode for human readability. This is almost always what you want.
Scanner Compatibility
Not all scanners read all symbologies. Before deploying barcodes, verify that your scanners support your chosen format.
Most modern scanners support Code 128 and Code 39 without configuration. Older scanners might need symbology enabled in settings. Smartphone apps generally support common symbologies but may struggle with damaged or poorly printed barcodes.
Scanner distance matters. Handheld scanners read at arm's length. Fixed-mount scanners (like those at checkout lanes) read at specific focal distances. Larger barcodes scan from farther away. Match barcode size to scanning distance.
Test in realistic conditions. A barcode that scans perfectly on your desk might fail when printed on glossy label stock. A barcode that scans in good lighting might fail in a dim warehouse corner. Test where barcodes will actually be used.
Beyond Linear Barcodes
Linear barcodes (the traditional bar patterns) work well for simple identifiers but have limitations. They encode limited data. They require line-of-sight scanning—you can't scan through plastic or read a damaged bar.
QR codes and other 2D symbologies encode more data in the same space. They include error correction—partially damaged codes still scan. They can encode URLs, contact information, or structured data.
For simple identification (SKUs, tracking numbers, asset IDs), linear barcodes remain ideal. For richer data (product URLs, configuration data, complex identifiers), consider QR codes instead.
Generate barcodes with the Barcode Generator API. Create QR codes with the QR Code Generator API. Build inventory and logistics systems that work at scale.
Originally published at APIVerve Blog
Top comments (0)