Blog

A Hidden Character Sits After the Lot Number When You Read a GS1 DataMatrix: Where the GS Separator Appears and Where It Doesn't

When you read a GS1 DataMatrix, the separator character GS (ASCII 29) between the lot number and the serial number is invisible on screen. I generated GS1 DataMatrix codes, read them back in the browser, and rearranged the AIs five ways to measure where GS appears and where it does not.

A GS1 DataMatrix on the left and the result field of the English GS1 DataMatrix Reader on the right. The decoded data shows <GS> between LOT123 and 21SER123.
The result in the English GS1 DataMatrix Reader. A GS separator follows the lot number.
Contents

When you read a GS1 DataMatrix and look at the text you imported, the serial number 21SER123 that should follow the lot number LOT123 seems to run straight into it, with no visible separator. Yet if you try to cut the string right after LOT123, it doesn’t split cleanly, or the length is one character longer than expected. In many cases the cause is the separator character GS (Group Separator, ASCII code 29), which is present at that position but not displayed on screen.

The GS1 DataMatrix Reader shows each GS in the decoded content as <GS> and also lets you copy the original data unchanged. In this article I generate codes with the GS1 DataMatrix Generator, read them back with this reader, and rearrange the AIs to see where GS is inserted and where it is not. Everything is processed in your browser; no image or input data is sent anywhere.

GS Appears When a Variable-Length AI Is Followed by Another AI

A GS1 DataMatrix holds the product number (GTIN), expiry date, lot number, serial number, and so on, each prefixed by a 2- to 4-digit number called an AI (Application Identifier). Some AIs have a fixed value length, and others have only a maximum length. The four AIs used in this article are as follows (per the GS1 General Specifications).

AI Meaning Value length
01 GTIN (product number) Fixed, 14 digits
17 Expiry date (YYMMDD) Fixed, 6 digits
10 Batch / lot number Up to 20 characters (variable)
21 Serial number Up to 20 characters (variable)

A reader has to know where each AI’s value ends. For a fixed-length AI the digit count tells it, but for a variable-length AI the string alone does not. So only when another AI follows a variable-length AI, a GS (FNC1 used in the middle of the data) is inserted as the separator. The last AI needs no separator, because the end of the code is the end of its value. The tool’s page also explains that in a GS1 DataMatrix, “an FNC1 used as a separator within the data is read as GS (ASCII 29).”

Reading Back a Generated Code to See Where GS Goes

1. Create a GS1 DataMatrix with the generator

Open the generator and enter the following string in the “GS1 data with AIs in parentheses” field. Each AI is enclosed in parentheses, with its value immediately after; the parentheses themselves are not stored in the code.

(01)09521234543213(17)271231(10)LOT123(21)SER123

Once you type it, the GS1 DataMatrix appears in the “Preview” on the right, with “22 × 22 modules / 208 × 208 px / 4 AIs” and a list of each AI’s value beneath it. Click “Save as PNG” to save gs1-datamatrix.png.

The English GS1 DataMatrix Generator. Four AIs are entered with parentheses in the input field, and the Preview on the right shows the code and the values of AI 01, 17, 10, and 21.
Enter AIs with parentheses. The generator adds FNC1 and GS automatically.

You do not need to type GS yourself. The tool inserts it automatically wherever a variable-length AI is followed by another AI.

2. Read the image with the reader

Next, open the GS1 DataMatrix Reader. Under “Image file (PNG, JPEG or WebP)”, choose the saved gs1-datamatrix.png with “Choose File”, and decoding starts immediately. For a physical label you can also use the camera with “Start camera”.

The image selection field of the English GS1 DataMatrix Reader, with the file name shown.
Decoding starts as soon as you choose an image. The image never leaves the browser.

3. Find the GS in the result

When decoding finishes, “Data with visible separators” under “Result” shows the following string.

01095212345432131727123110LOT123<GS>21SER123

From the start it reads 01 + GTIN, 17 + expiry date, 10 + LOT123, then <GS>, then 21 + SER123. In other words, a GS separator appears only after the variable-length lot number LOT123. The expiry date is fixed at 6 digits, so there is none after it (before 10).

The result area of the English GS1 DataMatrix Reader. The upper field shows the data with <GS>, the lower field shows the original data, and a small control-character symbol is visible where GS is.
The upper field makes GS visible as <GS>; the lower field is the original data. GS (ASCII 29) shows nothing on a normal screen.

Open “Show and select the raw data” and the original data appears under “Original decoded data (separators preserved)”. In that field a small symbol is visible where GS is. This is the single ASCII 29 character before it is replaced by <GS>. When you pass the data to another tool, click “Copy raw data” to copy it with the GS intact. If you instead copy the <GS> shown on screen, you paste the four-character text <GS>, which is not the original data.

Changing the Order of AIs Changes Where GS Goes

Whether GS appears depends on the arrangement, so I tried five orderings of the AIs. In each case I created the image with the generator and read it with this reader.

Input order (with parentheses) Displayed result Number of GS
(01)…(17)271231(10)LOT123(21)SER123 …1727123110LOT123<GS>21SER123 1
(01)…(10)LOT123(17)271231(21)SER123 …10LOT123<GS>1727123121SER123 1
(01)…(21)SER123(10)LOT123 …21SER123<GS>10LOT123 1
(01)…(17)271231(10)LOT123 …1727123110LOT123 0
(01)…(10)LOT123(21)SER123(17)271231 …10LOT123<GS>21SER123<GS>17271231 2

(… in the table stands for the leading 0109521234543213.)

Three things follow from the table. First, no GS is inserted after a fixed-length AI (01 or 17), whatever comes next. Second, a variable-length AI (10 or 21) gets a GS only when another AI follows it. Third, the same content can contain a different number of GS depending on the order, so you cannot say “there is always a GS after the lot number.” In the fourth row, where the lot number comes last, there is no GS at all.

Things to Watch For When You Process the Imported Data

Whether GS is present, and where, directly affects any program or spreadsheet that processes the data.

  • Split on GS, not by character count. Cutting by character count shifts positions on labels whose AIs are arranged differently. Read the AIs from the start, and for a variable-length AI take the value up to the next GS or the end of the string.
  • GS is an invisible control character, so the pasted text may look identical while its character count is off. If the count doesn’t match, check for control characters with the Invisible Character Checker.
  • The parentheses are not part of the code. The decoded string has no (01)-style parentheses. To restore the (01)…(10)… form, add them yourself following the AI length rules.
  • This tool reads and identifies the code. Even when the code is readable, it does not verify that the AI lengths, check digits, or combinations of AIs are correct.

Ordinary Data Matrix codes that are not GS1 can be read with the Data Matrix Reader. To create a code holding free text such as a control number, use the Data Matrix Generator (see the how-to article).

When the Code Won’t Read

If the image contains several codes, crop to just the one you want, leaving the quiet margin around it. If the code is small, glare-covered, or out of focus, retake the photo from the front and closer. If you read an ordinary Data Matrix, the reader shows a message saying it could not confirm GS1 DataMatrix identification. A GS1 DataMatrix begins with an FNC1 that marks the start of the data, and reading it adds the symbology identifier ]d2, so the reader checks for that before it displays a result.

For the details of the specification, see GS1’s General Specifications and the GS1 DataMatrix Guideline.

Frequently asked questions

Why can't I see the character between the lot number and the serial number when I read a GS1 DataMatrix?

When an AI with no fixed length (such as 10 for the lot number or 21 for the serial number) is followed by another AI, the control character GS (ASCII 29) is inserted as a separator. GS is not displayed on screen, so it stays invisible even if you copy and paste the decoded result.

Are there GS1 DataMatrix codes without GS?

Yes. If the code contains only fixed-length AIs (such as 01 for the GTIN or 17 for the expiry date), or if a variable-length AI comes last, no GS is inserted.

Is it safe to put any data into the reader?

The reader on this site decodes images entirely in your browser and does not send images or data anywhere. Still, if an image shows real lot or serial numbers, check what is visible in it before sharing it outside your company.