Manually Creating Barcode Strings for EAN-13 and UPC-A Barcodes

EAN-13 and UPC-A barcodes are widely used to identify retail items. The barcodes encode 13-digit and 12-digit number respectively. At the first glance, it is easy to create them. Unfortunately if you are using the font-based solution, it is not that easy as you may think. There are a couple of reasons:

  • To allow space efficiency, the same digit is coded with different patterns depending on its position in the barcode.

  • The same bar/space pattern may have or not have underlying text.

  • At last, font design requires every pattern to be represented by an unique character. You can not have one character representing multiple patterns.

As a matter of the complicity, we found that we have to use all printable ASCII characters, plus 10 extended characters to represent all bar/space patterns. This character set is far larger than the 10-digit numeric set. For every digit, there are five different encodings:

  • Left-hand Odd (LO)

  • Left-hand Even (LE)

  • Right-hand (R)

  • Supplement Odd (SO)

  • Supplement Even (SE)

In addition to the encodings, the unqiue printing requirement adds three variants to exsiting patterns:

  • With text below

  • Without text below

  • With text above

To allow user easily derive the encoding, we use a standard US-English keyboard [1] to map patterns to characters.

Figure 1. Character Mapping as laid out on a standard keyboard

Character Mapping as laid out on a standard keyboard

A. To print left-hand odd encodings without below text, use the first line of characters on a keyboard:

! @ # $ % ^ & * ( )

B. To print left-hand odd encodings with below text, use the second line of characters - that is, numbers 0-9:

1 2 3 4 5 6 7 8 9 0

C. To print left-hand even encodings without below text, use the third line of characters in captial case:

Q W E R T Y U I O P

D. To print left-hand even encodings with below text, we still use the third line of characters, however in lower case:

q w e r t y u i o p

E. Right-hand encodings do not have even/odd parity. To print right-hand encodings, use the fourth line. Captial letters print patterns without below text: [2]

A S D F G H J K L :

F. And lower case letters print patterns with underlying text:

a s d f g h j k l ;

G. Supplemental encodings use the last line, with capital letters printing odd encodings:

Z X C V B N M < >

H. And lower-case letters print even encodings:

z x c b n m , .

I. At last, these text-only symbols are printable with extended characters with values ranging from 0xc0 ~ 0xc9:

À Á Â Ã Ä Å Æ Ç È É

Because all printable ASCII characters are used up, we have to map these symbols to extended characters. On systems that a different character set other than Latin 1 is used, you will need to enter their corresponding characters. For example, in Eastern European languages (Windows code page 1250), character U+0154 (Latin character R with Acute) correspondes to value 0xc0.

Now that we have introduced character mappings, we proceed to explain how EAN-13 and UPC-A are encoded.

EAN-13 Encoding

An EAN-13 barcode encodes a 13-digit number. This number has a check digit at the end based on modulo 10 algorithm. Using Morovia UPC/EAN/Bookland fonts, a total number of 15 characters are needed to encode the whole barcode symbol, as depicted below:

Figure 2. Anatomy of an EAN-13 Barcode

Anatomy of an EAN-13 Barcode

The 16 characters are divided into six parts, as follows:

  1. Leading character, encoded with scheme I;

  2. Start character, represented by open square bracket symbol [;

  3. Left-hand encodings

  4. Central-guard character, represented by the virtical bar symbol |;

  5. Right-hand encodings

  6. Stop character, printable with close square bracket symbol ].

Leading Character

The leading character uses mapping scheme I. The character corresponding to this pattern is É, character value 0xc9. On Windows, this character can be entered by holding ALT key and using the numeric keyboard to type 201. Here 201 is the decimal value of 0xc9.

Start Character

The start character follows the leading character immediately. To enter this character, type [ (open square bracket).

Left-hand Encodings

The next 6 characters encode the first 7 digits using the left-hand encoding scheme. You might wonder how it can be done - here is the trick: the first digit is not converted into any characters; however its value determines the parity of next 6 digits. Remember that left-hand encodings have two parities - even and odd.

Table 1. Left-hand Parity Lookup Table

First DigitSecond Digit Encoding3rd4th5th6th7th
0Left-hand Encoding, OddOddOddOddOddOdd
1OddEvenOddEvenEven
2OddEvenEvenOddEven
3OddEvenEvenEvenOdd
4EvenOddOddEvenEven
5EvenEvenOddOddEven
6EvenEvenEvenOddOdd
7EvenOddEvenOddEven
8EvenOddEvenEvenOdd
9EvenEvenOddEvenOdd

In our case, the first digit is 9, the encoding pattern for digit 2 to digit 7 should be OEEOEO according to the table above. Because all of them print human readable text below, the shcemes B and D are used. The left-hand odd encodings for digits 7 and 5 are themselves (7 and 5). The left-ahdn even encodings for digits 8, 0 and 3 are i, p and e respectively. Adding them all together we get the barcode string for this part: 7ip7e5.

Central Guard Character

The central guard character is printale using vertical bar |.

Right-hand Encodings

The right-hand encodings do not have parity. Since they all have text below, scheme F is used. Therefore, the barcode string for 200449 is haakds.

Stop Character

The stop character is mapped to close square bracket ].

Putting Altogether

Adding all the parts we derived so far, we get the complete barcode string for EAN-13 number 9780735200449 - É[7ip7e5|haakds]. Format this string with Morovia UPC/EAN/Bookland fonts you will get a complete barcode. Below shows the barcode with font typeface MRV UEBMA, 18 points:

UPC-A Encoding

A UPC-A barcode encodes 12 digits with the last digit served as check digit. The UPC-A encoding is very similiar to EAN-13, except the following differences:

  • UPC-A implies a country prefix 0. From Table 1, “Left-hand Parity Lookup Table”, it means that the first 6 digits are all encoded with odd parity.

  • The first digit is converted into bar/space patterns, however, it does not have below text. The text is instead placed outside the barcode.

  • The last digit is also converted into bar/space patterns, however, it does not have below text either and the text is placed at the end of the barcode.

A UPC-A barcode string consist of 17 character, and is divided into 6 parts:

Figure 3. Anatomy of a UPC-A Barcode

Anatomy of a UPC-A Barcode

Leading Character

The leading character uses mapping scheme I. To print the text-ony symbol for digit 0, use extended character À (character value 0xc0).

Start Character

The start character is mapped to open square bracket [, in the same way as in EAN-13.

Left-hand Encodings

This portion actually contains 6 characters, the same as in EAN-13. Since UPC-A numbers have an implicit country code of 0, the encoding schema are all odd according to Table 1, “Left-hand Parity Lookup Table”. However, note that the first digit is encoded without human readable text below, so it must be coded in scheme A. Therefore, the barcode string for the first part 021898 is )21898.

Central Gaurd Character

The central guard pattern is printable using the vertical bar symbol |.

Right-hand Encodings

The following 6 digits are encoded with right-hand encoding schema. The first 5 digits print their human readable text below and are coded in schema E. However, the last digit does not print text below, so it must be coded with schema F. Therefore, the barcode string for 623812 is hsdkaS.

Trailing Character

The last digit of a UPC-A number also has a text form which uses mapping scheme I. Digit 2 is mapped to Â.

Stop Character

The stop character is mapped to close square bracket ].

Putting Altogether

Adding all the parts we derived so far, we hae the complete barcode string for UPC-A number 021898623812 - À[021898|hsdkaS]Â. Format this string with a Morovia UPC/EAN/Bookland font you get a complete barcode. Below shows the barcode with font typeface MRV UEBMA, 18 points:



[1] Keyboards in other languages may have different layouts.

[2] When applying on punctuation symbols, the "capital" means that these characters are accessed by pressing the key while holding the Shift. For example, collon : is in the same class as upper case A while semicolon ; is in the same class as lower case a.