The 5 digit ZIP codes were introduced by the U.S. Postal Service in 1963. "ZIP" stands for **Z**oning **I**mprovement **P**lan, and the code was invented by Robert Aurand Moon in the 1940's. A ZIP code is a structured number which helps to locate the address being mailed to. The country is divided into 10 zones, and the first digit of the ZIP code tells you which zone the mail is to be sent to. The next two digits specify the metropolitan area or regional center in that zone and the last two digits indicate the local post office (or postal zone in larger cities). In 1983 the postal service increased the size of ZIP codes to 9 digits and called the extended code the ZIP + 4 code. The new digits further refine the address within the local post office area. Recently, the Post Office has added two more digits, creating an 11 digit Delivery Point code.

The Post Office started to use bar codes in 1965 to automate the sorting process. There are many different bar codes used today for different purposes. The bar code that the Post Office uses is called **PostNET** (which stands for **Post**al **N**umerical **E**ncoding **T**echnique). While the PostNET bar code is not meant to be read by humans, if you know the rules for how it is formed, you *can* read it - with a little patience.

Let's start by looking at a 5-digit ZIP code (the same rules apply to the larger 9-digit and 11-digit codes). Here is an example:

There are 32 lines in this PostNET bar code. The first and the last are always long and they mark the beginning and end of the code (this is useful for the machines, but is not really part of the code). The remaining 30 lines are broken up into 6 groups of 5 lines apiece. Notice that in each of theses groups of 5 lines there are exactly 2 long lines and 3 short lines. Each of these groups represents a single number digit and where the 2 long lines appear tell you which digit is represented. The table below shows which which digit is associated with the patterns of long and short lines.

Read the following PostNET codes:

Click here to see the answers.

Now that we can read a PostNET bar code we notice a funny thing. The PostNET bar code represents 6 digits for a 5 digit ZIP code (and 10 digits for a 9 digit ZIP + 4 code, or 12 digits for an 11 digit Delivery Point code). If you compare a known ZIP code with its PostNET bar code, you will see that the last digit is the mystery number (our example above was for the ZIP code 56458). This mystery number is added to the bar code to help the machines that read the code detect errors in the reading process. The mystery number is called a * check* (or

In our example with the ZIP code 56458 we calculate the check digit like this:

Then, in order to go up to the next multiple of 10 (which will be 30), we need to add

So

Calculate the check digit for these zip codes:

- 28014
- 52923
- 10011-4211

A natural question to ask is *why*? Why is a check digit added in the PostNET bar code? The answer has to do with the fact that the bar codes are created and read by machines and not humans. All sorts of problems can occur in these automatic systems that would cause a ZIP code to be read incorrectly. Dust and paper particles can get into the optical readers, the ink can smear or run out in the printers, or the envelopes may be greasy or made of poor quality paper - to mention just a few problems. A check digit helps the reading machine to determine if a mistake has been made. These machines work by adding up all the digits of the bar code. A correct bar code will add up to a multiple of 10, so if this happens then most likely no error has been made, but if it doesn't then an error has definitely occurred. When this happens, the piece of mail is sent to a human to check it out.

If the bar code for a 5-digit ZIP code is read as 112233 then the reader would calculate the sum of all the digits and get 12, not a multiple of 10, so the machine will know that something is wrong.

**Exercises 3:**

Which of these bar codes would be sent to a human to find the error?

- 123456
- 542315
- 02323-87313

We can now ask, how good is this error detection scheme? If just one error is made, that is, one digit is not read correctly, then the check digit idea will always detect the error. It is not possible for the machine to find out where the mistake is made, but it will know that one occurred. If more than one error is made, this scheme will often detect the fact, but it is possible that several errors can go undetected. For instance, if the correct bar code 112231 is read as 117731, then the procedure will not detect any error because sum of the incorrect bar code will be 20. Notice that in this example, the numerical sum of the errors is 10 (each 2 was changed to a 7, so there were two errors of 5, giving the sum 10). When the sum of the errors is a multiple of 10, the scheme will not notice any error. Also notice that the errors can be both positive and negative, so they must be added as signed numbers. Thus, if the correct bar code 112231 is misread as 121231, then the error in the second digit is +1 and the error in the third digit is -1, so the sum of the errors is 1 - 1 = 0, and these errors will be undetected.

**Exercises 4:**

Change these correct PostNET codes to incorrect ones which would not be detected as errors.

- 478416
- 034823
- 28462-29377

We mentioned above that the scheme always detects a single digit error. This is true because the biggest error that can be made in a single digit is 9 (if a 0 was changed to a 9) and the smallest is -9 (when a 9 is changed to a 0). Thus, the range of error values for a single digit error is from -9 to +9, and the only multiple of 10 in this range is 0. But if 0 is the error, then no error has been made!

**Homework:**

You probably know your own ZIP code, and you may even know your ZIP + 4 code, but it is very unlikely that you know your Delivery Point code, since this is not printed and only appears in the bar code. Find a piece of mail sent to your home that has the long (62 bars) PostNET code. Read the last three digits. The very last digit is a check digit (check this out!) and the other two are the new ones added to your ZIP + 4 code to get the Delivery Point code.

Answers to Exercise 1

- 804214
- 123455
- 800273

Answers to Exercise 2

- 5
- 9
- 9

Answers to Exercise 3

- digit sum is 21, so this is not correct.
- digit sum is 20, so this is correct.
- digit sum is 32, so this is not correct.

Possible answers to Exercise 4

There are many possible answers, here are just a few examples:

- 478966 (add 5 to the 3rd and 4th digit)
- 323723 (add 3 to the first, subtract 1 from the next 3 digits)
- 17351-18266 (subtract 1 from each digit)