EAN13 is a standard describing a barcode symbology and numbering system used in global trade to identify a specific retail product type, in a specific packaging configuration, from a specific manufacturer. The standard has been subsumed in the Global Trade Item Number standard from the GS1 organization; the same numbers can be referred to as GTINs and can be encoded in other barcode symbologies defined by GS1. EAN barcodes are used worldwide for lookup at retail point of sale, but can also be used as numbers for other purposes such as wholesale ordering or accounting.

Each EAN bar code character is comprised of two bars and two spaces. The wide elements are multiples of the narrow elements. Wide elements are composed of one, two, three, or four narrow elements. There are a total of seven elements in each EAN character.

An EAN 13 symbol consists of a start character, a flag character, the left side data field, the left bar character, the right side data field, the check digit and stop character.

The start character is used at the beginning of the symbol to provide the bar code reader with start instructions. The start character pattern is 101.

The right side data field consists of six even parity characters: five digits plus the modulus 10 check digit.

The checksum is calculated as sum of products - taking an alternating weight value (3 or 1) times the value of each data digit. The checksum digit is the digit, which must be added to this checksum to get a number divisible by 10 (i.e. the additive inverse of the checksum, modulo 10). See ISBN-13 check digit calculation for a more extensive description and algorithm. The Global Location Number(GLN) also uses the same method.

The checksum (last digit in the barcode) is a Modulo 10 calculation:

Add the values of the digits in the even-numbered positions: 2, 4, 6, etc.

Multiply this result by 3.

Add the values of the digits in the odd-numbered positions: 1, 3, 5, etc.

Sum the results of steps 2 and 3.

The check character is the smallest number which, when added to the result in step 4, produces a multiple of 10.

Example: Assume the barcode data = 001234567890

0 + 2 + 4 + 6 + 8 + 0 = 20

20 * 3 = 60

0 + 1 + 3 + 5 + 7 + 9 = 25

60 + 25 = 85

85 + X = 90 (nearest equal or higher multiple of 10), therefore X = 5 (checksum)

Here is a sample Visual Basic function to calculate the checksum:

Function Append_EAN_Checksum (RawString as String)

Dim Position as Integer

Dim CheckSum as Integer

CheckSum = 0

For Position = 2 to 12 step 2

Checksum = Checksum + Val(Mid$(RawString, Position, 1))

Next Position

CheckSum = CheckSum * 3

For Position = 1 to 11 Step 2

CheckSum = CheckSum + Val(Mid$(RawString, Position, 1))

Next Position

CheckSum = CheckSum Mod 10

CheckSum = 10 - CheckSum

If CheckSum = 10 Then

CheckSum = 0

End If

Append_Ean_Checksum = RawString

Format$(CheckSum, "0")

End Function