Urgent.News

What's breaking now, across thousands of outlets.

Tech

Check digits explained: how barcodes catch a typo with one number

Every EAN-13 and UPC-A barcode ends in a digit that isn't data at all. It's a check digit, and it lets a scanner (or your code) reject most typos instantly. The EAN-13 rule Take the first 12 digits. Multiply them alternately by 1 and 3, starting with 1 from the left. Add it all up. The check digit is whatever brings the total up to the next multiple of 10. Example: 400638133393? digits: 4 0 0 6 3…

EAN-13 and UPC-A barcodes terminate with a digit that holds no information; it's a verification number known as the check digit. This digit helps a scanner or code detect most typing errors instantly.

For EAN-13, the process begins with the initial 12 digits. Each digit is then multiplied by either 1 or 3, alternating starting with 1 from the left. All the resulting products are summed. The check digit is the number that, when added to this sum, makes it a multiple of 10.

For example, consider the digits 400638133393. Multiplying them alternately by 1 and 3 gives: 4+0+0+18+3+24+1+9+3+9+9+9=89. The check digit is determined by subtracting the remainder of 89 divided by 10 from 10, then applying the operation again if necessary. In this case, the check digit is 1, making the full code 4006381333931.

In JavaScript, this process can be coded into a function. The function takes the first 12 digits as input, multiplies each by either 1 or 3, sums the products, and then calculates the check digit.

UPC-A uses a similar method, but it starts the weighting with 3 instead of 1 for the first digit. This scheme is designed to catch any one incorrect digit, although it may not catch all swaps of two adjacent digits. Some other systems, like ISBN-10, use a different method, applying a mod 11 calculation that can identify adjacent swaps. Credit card numbers, on the other hand, use a different algorithm known as the Luhn algorithm.

Barcodes are a simple yet effective system for error detection, but they're not foolproof. Other systems trade accuracy for complexity, providing stronger protection against errors.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Day 83: Two Files and Four Parts

Day 83 of DevOps, Day 33 of Azure. Both tasks today were made of parts that are each correct on their own and do nothing until something joins them.

  • Ansible inventory and playbook created for DevOps task
  • Load balancer configured with frontend IP, backend pool, health probe, and rule
  • Basic Load Balancer retired on September 30, 2025, Standard Load Balancer becomes standard

GitHub Actions paths and paths-ignore together on one event

Writing GitHub Actions paths and paths-ignore together on one event is documented as unsupported, but no published component rejects it, so the file compiles and the workflow runs.

  • GitHub Actions doesn't officially support paths and paths-ignore together.
  • Workflows with both filters compile and run, but outcome is undocumented.
  • Best practice is to choose one filter for desired outcome, test thoroughly.

More from Sunday 15 November →