LogicGates.org Open the simulatorSimulator

EAN-13 barcode generator

Type 12 digits to get the check digit and the barcode, or 13 to check one. Every bar is explained: which of the three codes draws each digit, where the first digit hides, and the 95 modules from guard to guard.

12 digits and the check digit is worked out; 13 and it is checked. An ISBN-10 such as 0-306-40615-2 is converted to its ISBN-13. Spaces and hyphens are ignored.

EAN-13 4 006381 333931 Check digit 1, worked out from the first 12 digits. Prefix 400: GS1 Germany issued the company prefix (not a country of origin).
4006381333931

Hatched: the quiet zones, 11 modules on the left and 7 on the right, left blank when printed.

Digit by digit

Hover over the bars, or focus a digit below, to see which modules it owns; click or tap a digit to keep it lit, and press Escape to let go. The first digit has no bars: it picks the L and G pattern of the next six.

EAN-13: 95 modules between the quiet zones, 113 with them.

All 95 modules

Start 101 0 L 0001101 0 G 0100111 6 L 0101111 3 L 0111101 8 G 0001001 1 G 0110011 Centre 01010 3 R 1000010 3 R 1000010 3 R 1000010 9 R 1110100 3 R 1000010 1 R 1100110 End 101

1 is a bar module, 0 a space. Add 11 spaces on the left and 7 on the right for the quiet zones.

Check digit working

Digit 400638133393
× weight 131313131313
Product 40018324193999
  1. 4 ×1 4
  2. 0 ×3 0
  3. 0 ×1 0
  4. 6 ×3 18
  5. 3 ×1 3
  6. 8 ×3 24
  7. 1 ×1 1
  8. 3 ×3 9
  9. 3 ×1 3
  10. 3 ×3 9
  11. 9 ×1 9
  12. 3 ×3 9

Sum 4 + 0 + 0 + 18 + 3 + 24 + 1 + 9 + 3 + 9 + 9 + 9 = 89. The next multiple of 10 is 90, so the check digit is 90 − 89 = 1.

How an EAN-13 barcode is put together

An EAN-13 (originally European Article Number, now International Article Number) is the barcode that carries a 13 digit GTIN-13. It is drawn on a grid of equal-width columns called modules. Each module is either dark or light, so the whole symbol is a string of bits: a bar is a run of 1s and a space a run of 0s, and a bar can be one to four modules wide. At the nominal size a module is 0.33 mm.

Part EAN-13 UPC-A EAN-8
Left quiet zone 11 9 7
Start guard 101 3 3 3
The left-hand digits, 7 modules each 42 42 28
Centre guard 01010 5 5 5
The right-hand digits, 7 modules each 42 42 28
End guard 101 3 3 3
Right quiet zone 7 9 7
Total 113 113 81

The guards are fixed patterns: 101 at each end and 01010 in the middle. They give a scanner a reference width for one module and mark where each half starts. On a printed label they are drawn longer than the other bars, which is why they poke down between the digits. Between the guards there are always 95 modules, whatever the number.

The three codes: L, G and R

Every digit is drawn as 7 modules: two bars and two spaces. There are three ways to draw each digit. The L code (set A in the specification) is used on the left, R (set C) on the right, and G (set B) is a second choice on the left of an EAN-13. R is L with every module inverted, and G is R read backwards.

Digit Lcode (left) Gcode (left) Rcode (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
  • Left codes start with a space, right codes with a bar. Every L and G code begins with 0 and ends with 1; every R code is the other way round.
  • Parity tells the sets apart. Each L code has an odd number of dark modules (3 for 0), each G and R code an even number (4 for 0). A scanner that counts them knows which set a digit came from.
  • Direction comes free. The first digit after the start guard is always an L code, which is odd. Read backwards, the first code a scanner meets is an R code reversed, which is even, so it knows to flip the symbol round. That is how a checkout scanner reads a product held either way up.

Where the 13th digit hides

Twelve digits get bars, but an EAN-13 has thirteen. The first digit is never drawn. Instead it decides, for each of the six left-hand digits, whether the L or the G code is used, and a scanner reads it back from that pattern. The right half always uses R.

First digit Left six digits use First digit Left six digits use
0 LLLLLL 5 LGGLLG
1 LLGLGG 6 LGGGLL
2 LLGGLG 7 LGLGLG
3 LLGGGL 8 LGLGGL
4 LGLLGG 9 LGGLGL
First digit Left six digits use
0 LLLLLL
1 LLGLGG
2 LLGGLG
3 LLGGGL
4 LGLLGG
5 LGGLLG
6 LGGGLL
7 LGLGLG
8 LGLGGL
9 LGGLGL

In the default example, 4006381333931, the first digit is 4, so the left half reads LGLLGG: 0 as L, 0 as G, 6 as L, 3 as L, 8 as G, 1 as G. A first digit of 0 gives all L, which is a plain UPC-A; that is how EAN-13 was made to include the older American code without changing any bars.

Working out the check digit

Weight the digits 1, 3, 1, 3 and so on, counting so that the digit next to the check digit gets 3. Add the products, and the check digit is what is needed to reach the next multiple of 10. For an EAN-13 the weights start with 1 on the first digit; for a 12 digit UPC-A they start with 3, which is the same rule seen from the other end.

EAN-13 5901234123457

5×1 + 9×3 + 0×1 + 1×3 + 2×1 + 3×3 + 4×1 + 1×3 + 2×1 + 3×3 + 4×1 + 5×3
= 5 + 27 + 0 + 3 + 2 + 9 + 4 + 3 + 2 + 9 + 4 + 15
= 83

Next multiple of 10: 90, so the check digit is 7. Try it

ISBN-13 9780306406157

9×1 + 7×3 + 8×1 + 0×3 + 3×1 + 0×3 + 6×1 + 4×3 + 0×1 + 6×3 + 1×1 + 5×3
= 9 + 21 + 8 + 0 + 3 + 0 + 6 + 12 + 0 + 18 + 1 + 15
= 93

Next multiple of 10: 100, so the check digit is 7. Try it

UPC-A 036000291452

0×3 + 3×1 + 6×3 + 0×1 + 0×3 + 0×1 + 2×3 + 9×1 + 1×3 + 4×1 + 5×3
= 0 + 3 + 18 + 0 + 0 + 0 + 6 + 9 + 3 + 4 + 15
= 58

Next multiple of 10: 60, so the check digit is 2. Try it

Because 3 and 1 are both coprime to 10, changing any one digit always changes the sum by something that is not a multiple of 10, so every single-digit mistake is caught. Swapping two neighbouring digits is caught too, unless they differ by exactly 5: 0↔5, 1↔6, 2↔7, 3↔8, 4↔9. Those 5 pairs out of 45 change the sum by a multiple of 10.

UPC-A and EAN-8

UPC-A (Universal Product Code) has 12 digits and is used in the United States and Canada. It is an EAN-13 whose first digit is 0: the bars of UPC-A 036000291452 and EAN-13 0036000291452 are identical. A UPC-A label prints its first and last digits small, outside the bars, and draws those two digits' bars long like the guards.

EAN-8 is the short version for small packs: 8 digits, four each side of the centre guard, all L on the left and all R on the right, so there is no hidden digit. Its 67 modules use the same codes, guards and check digit rule. EAN-8 numbers are allocated separately by GS1, not by shortening an EAN-13.

What the first three digits mean

The first two or three digits of an EAN-13 are a GS1 prefix. It identifies the GS1 member organisation that issued the company prefix to the brand owner. It is not the country where the product was made: a company registered in one country keeps its prefix for goods made anywhere. A few ranges have special uses instead. This table is a selection, not the full list.

PrefixIssued by or used for
000–019 GS1 US
020–029 Restricted circulation within a geographic region
030–039 GS1 US
040–049 Restricted circulation within a company
060–139 GS1 US
200–299 Restricted circulation within a geographic region
300–379 GS1 France
400–440 GS1 Germany
450–459 GS1 Japan
460–469 GS1 Russia
490–499 GS1 Japan
500–509 GS1 UK
540–549 GS1 Belgium & Luxembourg
570–579 GS1 Denmark
640–649 GS1 Finland
690–699 GS1 China
700–709 GS1 Norway
730–739 GS1 Sweden
754–755 GS1 Canada
760–769 GS1 Switzerland
800–839 GS1 Italy
840–849 GS1 Spain
870–879 GS1 Netherlands
880 GS1 Korea
890 GS1 India
900–919 GS1 Austria
930–939 GS1 Australia
940–949 GS1 New Zealand
977 Serial publications (ISSN)
978–979 Books (ISBN), the “Bookland” range

Every UPC-A, read as an EAN-13 with a leading 0, falls between 000 and 099. The restricted circulation ranges 020 to 029 and 200 to 299 are for use within a geographic region, with rules set by the local GS1 member organisation (often weighed or priced items labelled in store); 040 to 049 is for use inside a single company. None of them identify a product outside that scope.

Book barcodes: ISBN-10 to ISBN-13

Books use the 978 and 979 prefixes, sometimes called Bookland, and the EAN-13 printed on a book is its ISBN-13. ISBNs have been 13 digits since 2007. An older ISBN-10 converts by putting 978 in front and replacing its check character, which works differently: weights 10 down to 2, modulo 11, with X standing for 10.

ISBN-10 0306406152 to ISBN-13

978 + 030640615 = 978030640615
weighted sum 93, next multiple of 10 100
check digit 7: 9780306406157

The old check digit 2 is dropped. Try it

Only 978 numbers have an ISBN-10 equivalent; 979 numbers are new and exist only as 13 digits (979-0 is used for printed music, as the ISMN). Magazines and other serials use 977 followed by the first seven digits of their ISSN.

Common mistakes

  • Reading the prefix as a country of origin. 400 to 440 means the company prefix came from GS1 Germany, not that the product was made there.
  • Using a UPC-A as the first 12 digits of an EAN-13. A 12 digit UPC-A already has its check digit. Typing it into an EAN-13 generator adds a 13th digit and makes a different number; put a 0 in front instead.
  • Cropping the quiet zone. The blank margins are part of the symbol. Placing the code against an edge or a line of text can make it unreadable.
  • Scaling a small PNG. Stretched pixels make some bars a pixel wider than others. Use the SVG for print, or a PNG at a whole number of pixels per module.
  • Inventing numbers for real products. Shops and marketplaces expect a GTIN licensed from GS1. A number that merely has a valid check digit is not registered to anyone; the 200 to 299 range exists for in-store use.

Barcodes are bits drawn as stripes. For the same idea in two dimensions see the QR code generator; for bits as numbers and text, the binary converter and the ASCII table.

Questions

How is the EAN-13 check digit calculated?

Multiply the first 12 digits alternately by 1 and 3, starting with 1, and add the results. The check digit is whatever brings that sum up to the next multiple of 10. For 400638133393 the sum is 89, the next multiple of 10 is 90, so the check digit is 1 and the full number is 4006381333931.

Does the barcode prefix tell you the country of origin?

No. The first two or three digits say which GS1 member organisation issued the company prefix to the brand owner. A company registered with GS1 Germany gets a 400 to 440 prefix wherever its products are made, and a product made in Germany can carry any prefix.

What is the difference between UPC-A and EAN-13?

A UPC-A has 12 digits; put a 0 in front and it is an EAN-13 with exactly the same bars, because the first digit 0 selects the all-L pattern for the left half. 036000291452 as a UPC-A and 0036000291452 as an EAN-13 are the same symbol; only the digits printed underneath are arranged differently.

How do I turn an ISBN-10 into an ISBN-13 for the barcode?

Put 978 in front of the first nine digits, drop the old check digit and work out a new one with the EAN rule. 0306406152 becomes 978030640615 plus check digit 7, which is 9780306406157. Type an ISBN-10 into the generator and it does this for you.

Why does an EAN-13 barcode have 95 modules?

Twelve of the thirteen digits are drawn, six each side, at 7 modules each: 84. The start and end guards add 3 each and the centre guard 5, which makes 95. The first digit has no bars of its own; it is carried by the mix of L and G codes in the left half.

How much white space does a barcode need around it?

GS1 sets a minimum quiet zone of 11 modules on the left and 7 on the right of an EAN-13, 9 on each side of a UPC-A and 7 on each side of an EAN-8. Text or a box edge inside that space can stop a scanner from finding where the symbol starts.

What mistakes does the check digit miss?

It catches every single wrong digit. It misses a swap of two neighbouring digits only when they differ by 5, such as 0 and 5 or 1 and 6, because the weights 1 and 3 then change the sum by a multiple of 10. Two or more wrong digits can also cancel out.