Skip to content

How to read and validate a GS1 code: from raw data to field-by-field checks

The raw text a scanner returns, the invisible separator, field lengths, calculating the GTIN check digit by hand and checking the date: a step-by-step guide to validating a GS1 code.

3 min readGS1 · DataMatrix · 2D code · Validation

Showing a code to a scanner and seeing the "read" light is not validation. The scanner only says it decoded the symbol; it does not say whether the data inside follows the GS1 rules. The steps below show the order for checking a code in your hands, starting from the raw text.

1. What does the scanner return?

Most scanners type the decoded content as plain text, like a keyboard. Two things matter in that text. First, some scanners prepend a symbology identifier to the content: ]d2 for GS1 DataMatrix, ]C1 for GS1-128. This prefix is not data and must be removed before parsing. Second, the FNC1 character that separates fields (ASCII 29, "GS") is invisible on screen; some scanners do not transmit it at all, others replace it with another character. Do not build parsing software without knowing how the scanner is configured here.

2. Split the raw text into fields

An example content: 0109504000059118 17271231 10LOT42 [GS] 21A1B2C3 (written with spaces for readability; in reality it is contiguous). Parsing works by reading the application identifier (AI) at the start of each field:

  • (01) GTIN: fixed 14 digits
  • (17) expiration date: fixed 6 digits, YYMMDD
  • (10) batch: variable length, up to 20 characters
  • (21) serial number: variable length, up to 20 characters

Fixed-length fields need no separator after them; a variable-length field ends with a separator unless it comes last. In the example the batch (10) is not last, so a GS follows it; the serial number (21) is last.

3. Calculate the GTIN check digit by hand

The last digit (8) of the 14-digit GTIN 09504000059118 is the check digit. The calculation: multiply the first 13 digits, from right to left, alternately by 3 and 1 (the rightmost by 3), add them up, and the number that brings the total up to the next multiple of ten is the check digit. In the example the sum is 72, the next multiple of ten is 80, the difference is 8: the code is correct. With a 7 the symbol would still scan, but the GTIN would be invalid.

4. Check the date and the separators

  • The month under (17) must be 01-12. Day 00 means "last day of the month"; does your system handle that explicitly?
  • 271231 in the example is 31 December 2027. The same digits written out of a DD.MM.YY habit would give a valid but wrong date.
  • If there is no separator after a variable field, the date and batch get mixed into the serial number. A field longer than 20 characters, or an unexpected "17" sequence inside the serial number, is the symptom.

5. Keep readability and correctness apart

The print quality of the symbol (contrast, module size, quiet zone) is one problem; the correctness of the data is another. They are tested separately. Print quality needs a verifier device; for the data, the steps above are enough and can be automated in software for every pack.

Try it with the tool

Paste the content into our GS1 barcode decoder: it splits the fields and validates the check digit and the date. For the check digit alone there is the check digit calculator, and for field definitions the application identifier dictionary. The most common errors on the line have their own note: Five common errors in pharma serialization codes. To set up validation on your line, get in touch.

Let's discuss this for your plant