Skip to content

EPC encoding

This page is for the moment you go from reading tags to generating codes and writing them: your goods, your codes. You will learn what an EPC is assembled from, how to generate one that follows the GS1 standard, and the writing procedure that avoids producing wrong tags you cannot take back.

The authoritative documents are the GS1 EPC Tag Data Standard 2.3, ratified October 2025, and GS1 Tag Data Translation for machine-readable conversion rules. This page summarizes only what integration work needs; check detailed figures against those two documents.

From GTIN to EPC

Your system already has GTINs, the 13-or-14-digit barcodes identifying a product type. An EPC does exactly one more thing: it pairs the GTIN with a serial number to identify the individual item. The scheme retail uses most is SGTIN-96, packing that GTIN-plus-serial pair into exactly 96 bits:

A real example: the EPC hex 3034257BF7194E4000001A85 decodes to GTIN-14 80614141123458, serial 6789, equivalent to the Digital Link https://id.gs1.org/01/80614141123458/21/6789. Three notations, one item.

For quick experiments before writing code, Nextwaves provides web tools that encode and decode SGTIN-96 so you can eyeball the results.

Anatomy of SGTIN-96

The 96 bits split into five regions:

text
Header 8 | Filter 3 | Partition 3 | Company prefix + Item reference 44 | Serial 38
  • The header 0x30 says "this is SGTIN-96", telling readers which rules decode the rest.
  • The filter hints at packaging level, letting readers pre-filter: 1 is a point-of-sale item, 2 a case, 4 an inner pack, 6 a unit load, 7 a component, 0 everything else; 3 and 5 are reserved in the standard's table.
  • The partition states where the boundary between company prefix and item reference falls inside the shared 44 bits:
PartitionCompany prefix: digits / bitsItem reference: digits / bits
012 / 401 / 4
111 / 372 / 7
210 / 343 / 10
39 / 304 / 14
48 / 275 / 17
57 / 246 / 20
66 / 207 / 24

Pick the partition from the exact length of the GS1 Company Prefix your company was issued, taken from the GS1 paperwork, never guessed from data.

  • The 38-bit serial is yours to manage: allocate so it never repeats within one GTIN. The safest source is a counter in your database, just like the sequence issuing invoice numbers.

Generate and write

Four steps, and the SDK ships tools for every step after encoding:

  1. Encode the GTIN-plus-serial pair into an SGTIN-96 hex string, per the bit table above and the reference vectors in GS1 TDS.
  2. Validate the string before writing with validate_epc_hex, rejecting wrong lengths and characters early.
  3. Write to the tag with write_epc_tag. Before writing, the target tag must be singulated, meaning exactly one tag in the zone; writing with two tags present means not knowing which tag you just overwrote, see the glossary.
  4. Read back and compare with check_write_epc. This step cannot be skipped: a write that failed halfway leaves a tag carrying garbage, and only the read-back catches it.

Parameter details for the three functions live in the SDK reference, under EPC writing.

Other EPC schemes

SGTIN-96 covers retail items, but GS1 TDS defines schemes for other objects, recognized by the code's first header byte:

SchemeHeaderIdentifies
SGTIN-960x30Individual items: GTIN + serial
SSCC-960x31Shipping containers, pallets
SGLN-960x32Locations, with an extension
GRAI-960x33Returnable assets, like crates and plastic pallets
GIAI-960x34Individual assets, like equipment
GSRN-960x2DService relationships

If a tag's header is not in the table, go straight to GS1 TDS: the standard has longer variants too, such as SGTIN-198 carrying alphanumeric serials.

Before writing in bulk

Writing a few test tags is easy; writing thousands for production needs a tighter net, because wrongly written tags scattered through a warehouse are the most expensive kind of mistake to recall:

  • Normalize hex strings before processing: right length, right characters, right header, and leading zeros preserved through every step, spreadsheet intermediates included.
  • Verify the GTIN check digit and confirm the company prefix genuinely belongs to your company, per the GS1 paperwork.
  • Reject negative, fractional, empty, or out-of-range inputs outright.
  • Run decode(encode(x)) round-trips against GS1's official vectors before trusting your encoder.
  • Never write a tag before independently confirming the value belongs to the exact target item.
  • And always read back after writing, item by item, as in step 4 above.

The full sign-off list lives in the production checklist, under encoding and writing.

Easy Inventory operations and RFID integration documentation