The Mathematics
of Barcodes

Cracking Barcodes
The UPC a Scheme
Coding Errors

Teacher Copy


UPC-A Background for Mathematics Lessons

Universal Product Code (UPC) was established for the benefit of the food/supermarket industry to facilitate automatic scanning of item numbers with associated price look-up at the point of sale.  UPC is also utilized on all retail products sold.  The UPC-A system is a 12 digit code.  The code consists of a number system character, a 5-digit manufacturer identification number, a 5-digit item code number, and a check digit.  UPC-E is a 6 digit code that is found on beverage containers among other items, but will not be used in this series of lessons.

The number system character or data identifier, which is the first number in the code is typically located at the lower left hand side of the bar code and usually outside the bars and spaces.  There are currently 7 categories of the number system character. The "0" is assigned to all items except: "2" is designated for random-weight items such as meat and produce; "3" is used for companies which have been assigned their National Drug Code Number as their UPC; "4" is assigned for retailer use only; "5" is designated for coupons; and "6" and "7" are used for industrial applications including retail applications where they serve the same function as "0".

Important Notes Regarding UPC:

  • It codes only numbers from 0 to 9.
  • A narrow dark bar indicates a binary one and a narrow white space a binary zero.
  • A bar or space may be from 1 to 4 spaces wide.
  • Each digit is coded by 2 bars and 2 spaces occupying a total of 7 spaces.
  • Digits to the left of the center pattern are coded space-bar-space-bar.
  • Digits to the right of the center pattern are coded bar-space-bar-space.
  • Each digit has two binary codes.  One is for the left hand of the center pattern and one for the right.
  • Digits to the left of the center pattern are made up of an odd number (3 or 5) of binary ones (odd parity) and the digits on the right are made up of an even number (2 or 4) of binary ones (even parity).
  • The binary number that is the used for each number is the binary code, not the binary representation for that number.
  • The check digit is the twelfth digit encoded into the symbology but is not necessarily printed in numeral form.
  • Each bar code consists of a right and left quiet zone, a right and left guard pattern, a center pattern and of course the twelve number codes.
  • The quiet zone is 11 times the narrow bar width on the left and 7 times the narrow bar width on the right.
  • The guard pattern for each side is bar-space-bar (101).
  • The center pattern divides the 12 numbers in half and consists of space-bar-space-bar-space (01010).
  • A complete UPC-A symbology is made up of 30 bars and 29 spaces.
  • The complete symbology including quiet zones at 100% magnification is approximately 1.5 inches horizontally and 1.0 inches vertically.

Number value Left characters (odd parity)  Right characters  (even parity) 
0 0001101 1110010 
0011001 1100110 
0010011  1101100 
0111101  1000010 
0100011 1011100
0110001  1001110 
0101111  1010000 
0111011  1000100
8 0110111 1001000 
9 0001011  1110100
GUARD BARS  101 101 
CENTER                             01010 


Statistics: Lesson could focus on entry errors such as approximately 1 in 300 for human keyboard entry and 1 in 3,000,000 for bar code entry.  Students could collect data from users of keyboard entry and bar code scanners that would either validate or dispute these statistics.  Data on the cost to the company for these kinds of errors could be collected.  Another set of statistics that could be compiled is the cost of personnel for the various means of data entry as opposed to the cost of the technology being used.  Students could then make conclusions concerning their findings as to the most cost-efficient means of data entry.

Statistics: Lesson could focus on the cost of various kinds of scanners (hand-held wand about $100, helium-neon $600-$2000,...), the error-rate of each or the error-rate of the operator of each, and the type of material being scanned (low-priced retail goods or blood in a blood bank).  Students in this applied problem would have to gather the information, set up some guidelines, make a decision, and then justify it to the "board."

ISBN Code: The International Standard Book Numbers are a number code that includes a language or nation indicator, a number for the publisher, a number for the published article or book itself, and a check number.  The check number is based on a modulo 11 scheme.  A lesson of this type would utilize equation solving skills and modular arithmetic.

Code 39: The "3 of 9" code scheme utilizes 3 wide elements (bars or spaces) and 6 narrow ones.  It allows more characters to be coded (44 in all) and may also have a check number.  Have students compare code 39 to the UPC-A system.

Developing a Bar Code: Students could be challenged to create a bar code that utilized 2-D symbology (for example, the length and width of the bars would hold meaning instead of just the width).

Left-Right Parity: Students could investigate the coding scheme in UPC-A where the left-right parity is of utmost importance in terms of bi-directional scanning. Some of the findings might include the total amount of "barred" space for any number when the left and right codes are combined is seven, with every "place" having a bar and that the left-hand code has an odd number of bars (3 or 5) while the right-hand code has an even number of bars (2 or 4).  Also, the seven spaces allowed for each number are always filled by 2 bars and 2 spaces of width varying from 1 to 4 spaces wide.  A question that could be posed is, "Are there any more characters could be coded using the existing UPC-A scheme?"


Gallian, J. A., The Mathematics of Identification Numbers, The College Mathematics Journal 22 (1991) 194-202.

Gallian, J. A. and S. Winters, Modular Arithmetic in the Marketplace, American Mathematical Monthly 95 (1988) 548-551.

Gumm, H. P., A New Class of Check Digit Methods for Arbitrary Number Systems, IEEE Transactions on Information Theory 31 (1985) 102-105.
Gumm, H. P., Encoding of Numbers to Detect Typing Errors, International Journal of Applied Engineering Education 2 (1986) 61-65.

Jacobs, Harold R., Mathematics: A Human Endeavor, San Francisco: W.H. Freeman and Company (1982) 378-409, 510-517.

Knill, George, International Standard Book Numbers, Mathematics Teacher 74 (1981) 47-48.

Peck, Lyman C., Secret Codes, Remainder Arithmetic and Matrices, Reston, VA: National Council of Teachers of Mathematics (1975) 1-11, 29-35.

Thornton, Davey S., Check Out UPCs, 80 Micro 46 (1983) 114-120.

Wood, Eric F., Self-checking Codes--An Application of Modular Arithmetic, Mathematics Teacher 80 (1987) 312-316.

© Copyright
Area 10 Mathematics and Technology Professional Development Center
Permission is granted to duplicate these materials for classroom use.

Last updated on 1/30/1999