Guide · Python · SDK · REST API

GLN Validation in Python — GS1 Check Digit and Prefix Lookup

GLN (Global Location Number) is the GS1 standard for identifying physical and digital locations in supply chains. Here's how the check digit works, what the prefix encodes, and how to validate GLNs reliably in your Python application.

1. What is a GLN?

GLN stands for Global Location Number — a 13-digit identifier managed by GS1, the same standards body behind EAN barcodes and GTINs. While EAN identifies products, GLN identifies locations: warehouses, retail stores, loading docks, hospital departments, or even digital endpoints like EDI mailboxes.

Every participant in a GS1-enabled supply chain — from manufacturers to retailers to logistics providers — uses GLNs to unambiguously identify where goods are shipped from, shipped to, and stored. GLNs appear in purchase orders, advance shipping notices (ASN), invoices, and GS1-128 barcodes on pallet labels.

A single company can have hundreds of GLNs — one for headquarters, one per warehouse, one per department — all sharing the same GS1 company prefix but with different location references.


2. GLN structure — 13 digits decoded

0614141000036
Segment0614141000036
RoleGS1 PrefixCompanyLocation RefCheck

GS1 Prefix (2–3 digits) — identifies the GS1 Member Organisation that assigned the company prefix. For example, 061 is assigned to GS1 US.

Company Prefix (variable) — uniquely identifies the company within the GS1 system. The length varies (4–8 digits) depending on how many identifiers the company needs.

Location Reference (variable) — assigned by the company to identify a specific location: a warehouse, a store, a department, or a digital endpoint.

Check Digit (1 digit) — computed using the GS1 mod-10 algorithm with alternating weights of 1 and 3. Catches single-digit errors and most transpositions.

ℹ️A GLN is always exactly 13 digits — the same length as an EAN-13 barcode. The GS1 prefix + company prefix + location reference always sum to 12 digits, plus one check digit.

3. GS1 check digit algorithm — alternating weights 1 and 3

GLN uses the same check digit algorithm as EAN-13 and GTIN — alternating weights of 1 and 3, applied right-to-left (or equivalently, starting with weight 3 at position 1 from the left for a 13-digit number).

Let's walk through 0614141000036:

Step 1 — Apply alternating weights (1 and 3) to the first 12 digits

Digit0614141000036
Weight131313131313
Product018112112100009?

Step 2 — Sum the products

0 + 18 + 1 + 12 + 1 + 12 + 1 + 0 + 0 + 0 + 0 + 9 = 54

Step 3 — Check digit = (10 − sum mod 10) mod 10

(10 − (54 % 10)) % 10 = (10 − 4) % 10 = 6

Last digit of GLN is 6 — valid GLN

# gln_check_digit.py — validate a GLN check digit
import re


def validate_gln(raw: str) -> bool:
    digits = re.sub(r"[\s-]", "", raw)
    if not re.fullmatch(r"\d{13}", digits):
        return False

    weights = [1, 3] * 6
    total = sum(int(d) * w for d, w in zip(digits[:12], weights))

    check_digit = (10 - (total % 10)) % 10
    return check_digit == int(digits[12])


print(validate_gln("0614141000036"))  # True  ✓
print(validate_gln("0614141000037"))  # False ✗  bad check digit

4. Why GLN validation matters

EDI and electronic messaging

GLNs are mandatory in EDI messages (EDIFACT, X12, GS1 XML). An invalid GLN in a purchase order or invoice causes message rejection, delays shipments, and triggers manual exception handling. Validating GLNs before transmission prevents these failures.

Supply chain and logistics

Warehouse management systems (WMS), transport management systems (TMS), and order management systems all use GLNs to route goods. A corrupted GLN can send a shipment to the wrong warehouse or create phantom inventory records.

GS1-128 barcodes and pallet labels

GS1-128 labels on pallets encode GLNs using Application Identifier (AI) 410–415 to identify ship-to, ship-from, and bill-to locations. A bad check digit causes scan failures at receiving docks, delaying goods receipt and putaway.


5. The production-ready solution

The IsValid GLN API validates the format (exactly 13 digits), computes the GS1 check digit, and returns the GS1 prefix with the associated member organisation country.

GLN-13
Format
13-digit GS1 location number
<15ms
Response time
pure algorithmic check
100/day
Free tier
no credit card

Full parameter reference and response schema: GLN Validation API docs →


6. Python code example

Using the isvalid-sdk package or the requests library. Install with pip install isvalid-sdk or pip install requests.

# gln_validator.py
import os
from isvalid_sdk import IsValidConfig, create_client

iv = create_client(IsValidConfig(api_key=os.environ["ISVALID_API_KEY"]))

result = iv.gln("0614141000036")

if not result["valid"]:
    print("Invalid GLN")
else:
    print(f"Prefix: {result['prefix']}")           # → '061'
    print(f"Country: {result['prefixCountry']}")    # → 'United States'
    print(f"Check digit: {result['checkDigit']}")   # → '6'

In an EDI partner onboarding flow:

# Validate GLNs before storing trading partner locations
import re


def onboard_partner_locations(locations: list[dict]) -> list[dict]:
    results = []

    for loc in locations:
        if not loc.get("gln"):
            results.append({**loc, "gln_status": "missing"})
            continue

        check = validate_gln(loc["gln"])

        if not check["valid"]:
            results.append({**loc, "gln_status": "invalid"})
            continue

        results.append({
            **loc,
            "gln": re.sub(r"[\s-]", "", loc["gln"]),  # store normalised
            "gln_prefix": check["prefix"],
            "gln_country": check["prefixCountry"],
            "gln_status": "valid",
        })

    return results
Always store GLNs as strings, not integers — a GLN can start with zero (e.g. 0614141000036) and parsing it as a number would strip the leading zero.

7. cURL example

Validate a GLN:

curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://api.isvalid.dev/v0/gln?value=0614141000036"

Invalid GLN (bad check digit):

curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://api.isvalid.dev/v0/gln?value=0614141000037"

8. Understanding the response

Valid GLN:

{
  "valid": true,
  "prefix": "061",
  "prefixCountry": "United States",
  "checkDigit": "6"
}

Invalid GLN:

{
  "valid": false
}
FieldTypeDescription
validbooleanExactly 13 digits, all numeric, GS1 check digit passes
prefixstring2 or 3-digit GS1 prefix identifying the issuing member organisation
prefixCountrystringCountry or organisation associated with this GS1 prefix
checkDigitstringThe computed check digit (last digit of the GLN)

9. Edge cases

GLN-13 vs GTIN-13 (EAN)

GLN and EAN-13 (GTIN-13) share the same 13-digit format and the same check digit algorithm. The difference is semantic: an EAN identifies a product, a GLN identifies a location. You cannot tell them apart from the number alone — context determines which type it is. Always use the correct API endpoint for the identifier type.

# Same format, different meaning
product_code  = "5901234123457"  # EAN-13 → use iv.ean()
location_code = "0614141000036"  # GLN    → use iv.gln()

Prefix countries

The GS1 prefix indicates which GS1 Member Organisation issued the company prefix — not the physical location of the site identified by the GLN. A GLN with prefix 400 (Germany) can refer to a warehouse in Poland if the company registered its GS1 numbers through GS1 Germany.

Party GLN vs physical location GLN

GS1 distinguishes between a party GLN (identifying a legal entity or functional entity) and a physical location GLN (identifying a specific site or sub-site). Both are syntactically identical 13-digit numbers. The distinction is maintained in master data, not in the number format itself.

Leading zeros

GLNs frequently start with zeros — for example, US-issued GLNs often begin with 0. Never parse GLNs as integers or store them in numeric database columns. Always treat GLNs as fixed-length 13-character strings.


Summary

Do not parse GLNs as integers — leading zeros will be lost
Do not use GS1 prefix as physical location — it is the issuing GS1 member organisation
Use GS1 mod-10 check digit (alternating weights 1 and 3) for validation
Validate GLNs before EDI transmission to prevent message rejections
Store GLNs as fixed-length 13-character strings in your database
Distinguish between party GLNs and physical location GLNs in your master data

See also

Validate GLNs instantly

Free tier includes 100 API calls per day. No credit card required. GS1 check digit validation with prefix lookup.