EAN Barcode Generator - The Check Digit, the Ten Patterns, and Every Module It Paints
Type or paste an EAN-13, EAN-8 or UPC-A number and build the symbol one module at a time: the weighted sum behind the check digit with every product listed, the ten seven-module patterns the three code sets are derived from, a part-by-part table of guards and digits, quiet-zone and millimetre arithmetic, and a read-back that measures the painted bars and the pixels your own browser rasterised before it agrees the number is still in there. Nothing you type leaves this device.
The symbol, one rectangle per bar, with the digits written underneath
The last digit, worked out
| Position | Digit | Weight | Product | Running total |
|---|
Every piece of the symbol, in the order it is drawn
| Piece | What it carries | Modules | Widths a scanner measures |
|---|
What the symbol measures, in modules, pixels and millimetres
| The span | Modules | Pixels at the width you set | Millimetres at the X you set |
|---|
The ten patterns, and the two sets made from them
| Digit | Left code | Right code | The other left code | Ones in each | Widths of the left code |
|---|
Read back out of what your browser actually drew
| What was measured | How many times | What it came back as | Against the number typed in |
|---|
Where reading stopped, and why
| The thing it stopped on | What it says instead |
|---|
The arithmetic that chooses every bar
A symbol is a list of widths, not a picture of a number
An EAN symbol is a strip of ground divided into equal cells called modules, and every cell is either ink or
clear. Nothing about it is typographic: the bars are not strokes of a font and the digits underneath are a
courtesy to human readers, not part of the code. An EAN-13 is 95 modules from the edge of the first bar to
the edge of the last, and that number is not a measurement of anything printed - it is
3 + 7 x 6 + 5 + 7 x 6 + 3: a start guard, six digits at seven modules each, a centre guard, six more
digits, an end guard. An EAN-8 is the same shape with four digits per side, so 67. A UPC-A is twelve digits
drawn the way an EAN-13 draws thirteen, so 95 again. The piece-by-piece table lays those fifteen pieces out
in the order they are painted, and the modules column is the whole symbol when the rows are concatenated.
What a reader actually measures is not the cells but the runs: how many modules each bar lasts and how many
each space lasts, counted from the left edge. For 5901234123457 those runs are 59 wide-counts long, 30 of
them bars, and the widths are only ever 1, 2, 3 or 4 modules - 33 runs one module across, 18 two, six three,
two four. Ink covers 49 modules and clear ground 46. That asymmetry is why a symbol looks darker than a
barcode drawn from a different family, and it is also the reason a bad print is described as a lost module
rather than a lost digit: a reader that cannot tell a two from a three has not misread a number, it has
misread one edge of one bar.
The last digit is one division, and the working is printed
Take the twelve digits before the check digit, multiply them by 3, 1, 3, 1, … counted in from the right,
and add. For 590123412345 that is 83; 83 leaves 3 over when ten is taken out of it as many times as it
fits; the digit that carries 3 round to the next ten is 7, and the full number is 5901234123457. The
weighted table has one row per digit with its weight, its product and a running total, so the addition can
be checked with a finger. Two details in that arithmetic are worth knowing by heart. The last digit you
typed is always multiplied by three, never by one - which is why a single mistyped digit is so rarely
innocent. And when the sum divides by ten exactly, the check digit is 0, not 10, because it is a remainder
wearing the costume of a digit.
Leave the final digit out and the same table is drawn for the number you get back; type it in wrong and the answer and your digit are both shown, side by side, with the bars drawn from yours. That is on purpose. A retailer’s system will reject a number whose check digit does not agree, but a symbol printed from the number as written is the only honest way to show what a scanner would meet.
What that one digit is worth, and the one mistake it cannot see
Change one digit and the weighted sum changes by that digit’s weight times the error. The weights are 1 and
3, the error is one of 1 to 9, and neither 1 x error nor 3 x error is ever a multiple of ten - so the
remainder always moves, and a single mistyped digit is caught every time. Five hundred deliberate mistypes
in each of the three formats, and the check digit disagreed with the damaged number in all fifteen hundred
of them; not one slipped through.
Swap two neighbours and the sum changes by (b - a) x 3 + (a - b) x 1, which is 2 x (b - a). Two times
something is a multiple of ten when that something is five, so a swap is invisible exactly when the two
digits are five apart: 0 with 5, 1 with 6, 2 with 7, 3 with 8, 4 with 9, in either order. That is ten of the
ninety ordered pairs of distinct digits. Run the same experiment on swaps and 133 of 1,345 changed numbers -
just under one in ten - keep their check digit intact, against the eleven per cent the pairs allow for.
Nothing about the checksum can be improved here by trying harder; it is a property
of base ten and a weight pattern of 3 and 1. A transposed pair five apart is the failure this digit was
never designed to catch, and a number that has passed a check-digit test can still be exactly that mistake.
Every position in every one of the three formats was enumerated against the rule - 2,430 pairs of digits,
and the rule and the measurement agree on all of them.
Twenty patterns, and how far apart they are
Ten digits on the left of a symbol are drawn from ten seven-module patterns. Ten more are used on the right. There is a third set of ten. All three come from one table: the ten left patterns are fixed, the right ones are those same ten with ink and clear exchanged, and the third set is that exchanged pair read from the other end. The table on screen prints all three sets, so the derivation can be checked row by row; two properties of it are the load-bearing parts. Every left pattern holds three or five bars - an odd number - and every pattern in the other two sets holds two or four. And within any one set, the closest two codes are two modules apart: all forty-five pairs in each set were measured and none is a one-module neighbour.
That second property is what stops a damaged digit from being read as a different digit: to turn a 3 into a
6 drawn from the same set, two modules would have to change. Between the first set and the third, however,
the distance is sometimes one. The pattern for a 0 on the left is 0001101, and the pattern for a 4 in the
third set is 0011101: one module. So a scanner can absolutely look at a smudged 0 and see a 4 - it simply
cannot do it without leaving evidence, which is the next section.
The first digit draws no bars at all
An EAN-13 has thirteen digits and draws only twelve of them. The first is spent entirely on a choice: for each of the six digits on the left, whether to draw it from the first set or the third. That choice is written as a row of six letters, L or G, and there are exactly ten rows in use:
LLLLLL LLGLGG LLGGLG LLGGGL LGLLGG LGGLLG LGGGLL LGLGLG LGLGGL LGGLGL
row one belongs to digit 0, row two to digit 1, and so on. 5901234123457 starts with 5, which buys
LGGLLG, and the part-by-part table shows which of the six left digits were drawn as which set. A reader
works the other way: it decodes the twelve drawn digits, reads off the six letters, looks the arrangement up,
and gets the first digit back for free. If the letters match none of the ten rows, it has no number to
report at all.
Look at the rows for a second. One of them holds no G at all and the other nine hold exactly three. That is not a curiosity, it is the safety property: if a single module flips and changes one slot from an L pattern to a G pattern or back, the number of G letters becomes one, two, four or five, and no valid arrangement has any of those counts. One damaged module in the left half of an EAN-13 therefore cannot produce a misread number - it can only produce a symbol that spells nothing.
Damage, measured
Take symbols apart one module at a time and see what a strict reader says. Over 200 symbols of each format,
every module in turn inverted - 51,400 damaged symbols in all - not one was read as the number it was
painted from, and not one was read as any number at all. The refusals split into four kinds, and the split
is informative. For EAN-13’s 19,000 flips: 2,200 were inside a guard and broke a shape that is supposed to
be exactly 101, 01010, 101; 8,400 hit the right half, where only the second set is legal and a
one-module change never lands on a member of it; 4,818 hit the left half and landed on no pattern in either
of the two sets allowed there; and 3,582 landed on a real pattern and were refused for the reason in the
section above - the six letters they left behind spell no first digit. On EAN-8 and UPC-A the third bucket
splits again, because a G on their left half is illegal on its own rather than merely unusual.
Two damaged modules is a different story, and the honest limit of the design is worth a number rather than a shrug. In 15,841 EAN-13 symbols with two random modules inverted, 416 still read as a number, every one of those 416 read as the wrong number, and 17 of them carried a check digit that added up correctly. So one damaged symbol in thirty-eight survives double damage as a plausible-looking wrong number, and one in roughly a thousand escapes every structural rule and the checksum too. A reader built here refuses all of it loudly; a shop-floor scanner is free to guess, and when it does, those seventeen in fifteen thousand will look legitimate to the next system downstream.
Two formats, one set of bars
The first row of the ten arrangements is six L letters, and a UPC-A draws its whole left half as L. So an EAN-13 that begins with 0 draws exactly the bars of the UPC-A made from its last twelve digits - 500 random ones were compared and all 500 came out identical, bars and check digit both. The check digit agrees because the leading zero sits under a weight of 1 and contributes nothing to the sum. This is the reason the two names survive on the same packaging: a “UPC” with a zero in front is an EAN-13 and no printer needs to be told.
EAN-8 is the compact one: eight digits, 67 modules, four per half, and the left half confined to the first set. It is used for small packages, and the price of the shorter symbol is that the arrangement trick is gone - nothing in an EAN-8’s shape encodes a ninth digit, which is also why a G on its left is treated as damage rather than as information.
Size is arithmetic until it is ink
One module is whatever the printer makes it, so the geometry table gives three units and lets you convert by
hand. At 3 pixels per module, 5901234123457 is 285 pixels from the first bar’s edge to the last bar’s
edge and 351 across, including eleven modules of clear ground at each end. Ask for millimetres - 0.495 is a
common module width on a thermal printer - and the same spans become 47.025 mm and 57.915 mm. The quiet zone
is a control rather than a rule here: it can be set to zero, and then the width shown is exactly the width
of the bars and the gaps between them. Any number quoted as a specification minimum for guard spacing or
print contrast is deliberately not asserted, because none of it was measured; what is on screen is the
arithmetic of the modules you chose.
Fractional widths are where the picture and the number part company. A one-module bar at 0.5 pixels per module is half a pixel, and a rasteriser rounds it its own way; the read-back table samples the middle of each module out of the pixels the browser actually drew, decodes what it finds, and prints either “every one came back the colour it was painted” or how many modules came back wrong and what the reader made of the result. That row measures a browser rather than measuring arithmetic, which is why it says “your browser drew” instead of “the symbol is”.
What is not answered here
Three formats are drawn, and only three: EAN-13, EAN-8, UPC-A. They share one table of ten patterns, so the arithmetic on screen covers all of them without a second set of rules. Code 128, Code 39, ITF and DataMatrix are not here; a QR code is a different animal with error-correction codewords and it has its own tool. A check digit proves arithmetic, not assignment - nothing in these 95 modules says the number belongs to anybody or has been issued at all, so there is no prefix registry to consult and no claim made about whether the packaging is real. Print grade is not estimated either: an ANSI-style pass needs a measured print with a measured scanner, and a canvas on a screen is neither.
Everything above runs in the browser you are using, from the digits typed in, and the only inputs are the number, the format and the two or three size boxes. Nothing you type leaves this device - the tables, the picture, the report and the saved file are built from the same arithmetic that is printed beside them.