How to Decode a Barcode: Read the Bars by Hand
To decode a barcode, a scanner measures the widths of the dark bars and light spaces, turns each fixed-width group into a digit, and then checks the result against the last digit. You can do the same thing by hand. EAN-13 is the 13-digit barcode scanned at the checkout on retail products. Every digit in it takes up seven narrow units, and the very first digit is not drawn at all: it is hidden in the choice between two codes on the left. Below is the full method, with a worked example you can follow bar by bar.
Key takeaways
- An EAN-13 is 95 narrow units wide: two edge guards, a centre guard and twelve digits of seven units each.
- Each digit is two bars and two spaces. Left-half digits come in two versions, and the mix of versions across the six left digits gives you the first digit.
- The thirteenth digit is a check digit. If the arithmetic does not match, the scan was wrong.
- Decoding gives you a number and nothing else. A product name or price comes from a database lookup, not from the bars.
What decoding a barcode actually tells you
A barcode decoder returns two things: the type of barcode and the characters it carries. For a retail barcode that is a string of digits, such as 9520123456788. There is no product name, brand or price inside the bars. When an app shows those, it has taken the decoded number and looked it up somewhere else.
That matters when a search for a barcode comes back empty. The decoding worked; the number simply is not in the database you asked. It also explains why two apps can show different product details for the same barcode: they decode the same number but look it up in different places.
The layout of an EAN-13 barcode
Look closely at any EAN-13 and you will see three pairs of slightly longer bars: one pair at each edge and one pair in the middle. Those are the guard patterns. They tell the scanner where the code starts, where the halves meet and where it ends.
The whole symbol is built from a single narrow unit, called a module. A bar or space is one, two, three or four modules wide. Counted in modules, the layout is fixed:
| Part | Modules | Pattern |
|---|---|---|
| Start guard | 3 | bar, space, bar (101) |
| Left half: 6 digits | 6 × 7 = 42 | each digit starts with a space |
| Centre guard | 5 | space, bar, space, bar, space (01010) |
| Right half: 6 digits | 6 × 7 = 42 | each digit starts with a bar |
| End guard | 3 | bar, space, bar (101) |
| Total | 95 |
Twelve digits are drawn as bars. The thirteenth, the one printed on its own to the left of the code, has no bars of its own. You will see where it comes from in step 4.
The three sets of digit codes
Each digit is seven modules long and always made of exactly two bars and two spaces. Writing a dark module as 1 and a light one as 0, EAN-13 uses three sets of patterns. The right half always uses set R. The left half uses set L or set G, digit by digit.
| Digit | Set L (left) | Set G (left) | Set R (right) |
|---|---|---|---|
| 0 | 0001101 | 0100111 | 1110010 |
| 1 | 0011001 | 0110011 | 1100110 |
| 2 | 0010011 | 0011011 | 1101100 |
| 3 | 0111101 | 0100001 | 1000010 |
| 4 | 0100011 | 0011101 | 1011100 |
| 5 | 0110001 | 0111001 | 1001110 |
| 6 | 0101111 | 0000101 | 1010000 |
| 7 | 0111011 | 0010001 | 1000100 |
| 8 | 0110111 | 0001001 | 1001000 |
| 9 | 0001011 | 0010111 | 1110100 |
The sets are related in a simple way. R is L with every module flipped, and G is R written backwards. There is also a shortcut that saves you looking things up twice. Every L pattern has an odd number of dark modules, while every G and R pattern has an even number. Count the dark modules in a left-half digit, and you know which set it belongs to before you read the digit.
How to decode an EAN-13 by hand, step by step
You need the barcode at a size where you can count modules: zoom in on a clear photo, or print it large. Then work from left to right.
- Find the start guard. The first three modules are bar, space, bar. Everything after them belongs to the first digit.
- Cut the left half into six groups of seven. Measure the narrowest bar or space; that is one module. Write each group as ones and zeros.
- Read each left digit and note its set. Count the dark modules: odd means set L, even means set G. Then find the pattern in that column of the table.
- Work out the hidden first digit. Write the six letters you noted, for example L G G L G L, and look the sequence up in the table below.
- Skip the centre guard and read the right half. Six more groups of seven, all from set R.
- Test the check digit. The last digit must match the arithmetic in the section further down. If it does not, you have misread a group.
| Left-half sets | First digit | Left-half sets | First digit |
|---|---|---|---|
| LLLLLL | 0 | LGGLLG | 5 |
| LLGLGG | 1 | LGGGLL | 6 |
| LLGGLG | 2 | LGLGLG | 7 |
| LLGGGL | 3 | LGLGGL | 8 |
| LGLLGG | 4 | LGGLGL | 9 |
The first row is worth a second look. A leading 0 means every left-half digit comes from set L, which is exactly how a 12-digit UPC-A barcode is drawn. So an EAN-13 starting with 0 and the matching UPC-A have the same bars.
A worked example: 9520123456788
We generated an EAN-13 for 9520123456788, the example number used on the BWIPP barcode library's EAN-13 page, then decoded its 95 modules by hand. This is our own calculation, and the script that produced it is kept with this article's records.
| Group | Modules | Dark | Set | Digit |
|---|---|---|---|---|
| Left 1 | 0110001 | 3 | L | 5 |
| Left 2 | 0011011 | 4 | G | 2 |
| Left 3 | 0100111 | 4 | G | 0 |
| Left 4 | 0011001 | 3 | L | 1 |
| Left 5 | 0011011 | 4 | G | 2 |
| Left 6 | 0111101 | 5 | L | 3 |
| Right 1–6 | 1011100 1001110 1010000 1000100 1001000 1001000 | even | R | 4 5 6 7 8 8 |
The left half reads 5, 2, 0, 1, 2, 3, and its sets spell LGGLGL. In the first-digit table that sequence means 9. Put the hidden digit in front and add the right half: 9 520123 456788. As an independent check, we also ran the rendered image through zxing-cpp, an open-source barcode reader. It returned the same thirteen digits.
Checking your answer with the check digit
The last digit of an EAN-13 is calculated from the first twelve, so you can test a decoded number with pencil and paper. Starting from the left, multiply the digits alternately by 1 and 3, add everything up, and find the amount needed to reach the next multiple of 10.
For 952012345678: (9 + 2 + 1 + 3 + 5 + 7) = 27, and (5 + 0 + 2 + 4 + 6 + 8) × 3 = 75. The total is 102, so the next multiple of 10 is 110 and the check digit is 8. That matches the last digit we read, so the decoded number is valid.
What happens when one bar is misread
Barcodes have more than one line of defence. To see this, we flipped a single module in the third left digit of our example, as a smudge or a dropped ink spot might. The group 0100111 (a 0 from set G) became 0101111. That is a real pattern, but it belongs to set L, where it means 6.
The scanner would not get as far as the check digit. Swapping one G for an L turned the set sequence into LGLLGL, which is not one of the ten valid sequences in the table, so the read fails at once. A change that does land on a valid sequence still has to pass the check-digit test. A scanner accepts the number only when both tests pass, so a misread tends to show up as a failed scan. If yours keeps failing, our guide to why a barcode won't scan covers glare, focus and cut-off labels.
Decoding a barcode with your phone
Decoding by hand is slow. A phone does all six steps in a moment, and it reads many more barcode types than EAN-13. In ScanMint AI, open Scan Barcode, hold the label flat and fill the viewfinder with it. It reads twelve types: Code 128, Code 39, Code 93, Codabar, Data Matrix, EAN-13, EAN-8, ITF-14, UPC-A, UPC-E, PDF417 and Aztec. Scanned codes stay on your phone, in your scan history, and you can copy the number or search it for a quick lookup.
Scan Barcode works from the live camera only. There is deliberately no option to decode a barcode from a photo in your gallery, because a still image rarely holds the bar edges cleanly enough to read reliably. If the number is printed under the bars, type it in instead. If all you have is a picture, open it on a second screen and scan that with your camera. For a fuller walkthrough of the scanning side, see how to scan a barcode with your phone.
Going the other way is just as quick. Create Barcode turns a number into bars on the device, which is handy if you want a test code to practise decoding on. Our guide to printing a barcode that scans explains the sizes that keep the modules countable.
Other barcode types decode differently
The method above is specific to EAN-13 and its close relatives. UPC-A uses set L throughout the left half. EAN-8, made for small packaging, has four digits on each side read with sets L and R, and no hidden digit. Other types follow their own rules. Code 128 can carry letters and symbols as well as numbers and has its own pattern table. Code 39 is designed to be self-checking. Data Matrix is a two-dimensional code that stores data in a grid instead of in bar widths. The principle carries over, though: measure the elements, map each pattern to a character and confirm the result before trusting it.
Frequently asked questions
Can I decode a barcode without an app?
Yes, for EAN-13, UPC-A and EAN-8, using the tables in this guide and a clear, enlarged image. It is slow, but it is a good way to understand what a scanner does. For any other type, a scanner app is far more practical.
Does decoding a barcode tell me the price?
No. The bars carry only the number. Prices live in a shop's own system and change without the barcode changing.
Why does the number under the barcode sometimes look split up?
On an EAN-13, the first digit sits on its own to the left because it has no bars of its own. The other twelve are printed in two groups of six, under the two halves of the code.
What if my decoded number fails the check digit?
Then at least one group was misread. Recount the modules in each group, paying special attention to the wide bars and spaces. If you are scanning, clean the label or move closer and try again.
Try it on a barcode near you
Pick a packaged item with a 13-digit barcode, count the guards and read the first left digit by hand. Then open Scan Barcode in ScanMint AI and compare your answer with the scanner's.
Sources
- BWIPP (Barcode Writer in Pure PostScript) wiki, EAN-13 symbology page (retrieved 2026-11-30): EAN-13 as an extension of UPC-A, the leading digit encoded by mirroring left-half characters, and the example number 9520123456788.
- zxing-cpp, ODUPCEANCommon.cpp (L and G digit patterns) and ODMultiUPCEANReader.cpp (first-digit encodings), retrieved 2026-11-30.
- Our own encoding, hand-decoding and misread tests (python-barcode 0.16.1 and zxing-cpp), kept with this article's records.
Tools covered in this guide
Open any of these in ScanMint AI to follow along.
Related guides
- Mobile Barcodes: How to Make Them ScanWhy a barcode on your phone scans at one counter and not the next, and six fixes for brightness, size, margins, colours and glare, from our own decoder test.
- Why Won't My Barcode Scan? 9 Phone FixesA barcode that won't scan usually needs one clean, complete line across its bars. Nine phone fixes for glare, distance, curves and clutter, from our own decoding test, and what to do when nothing works.
- How to Print a Barcode That ScansPrint a barcode that scans first time: GS1 sizes for EAN-13 and UPC-A, how much blank margin to leave, which colours fail, and how to size codes for 203 and 300 dpi label printers.
Try ScanMint AI free
Turn your phone into a pocket scanner and PDF toolkit — 18 tools, privacy-first.
