Each type of barcode with fat and thin bars (UPC & code128 for example) use an algorithm to calculate the bars that represent the underlying digits. Many barcodes include checksum bars to help with possible errors when reading the bars. Code 3 of 9 barcode font (see related link), uses a set of bars for each digit 0-9, as well as each letter of the alphabet and a few symbol characters.
The US Post Office's POSTNET font is one of the few that I know of that is even close to human readable. It reads like this: a tall bar represents a 1 and a short bar represents a 0. The very first bar and very last bar are called frame bars and have no value. So starting with the second bar, each group of 5 bars represents a digit 0-9. Within each group of 5 bars, the bars have the following place values: 7,4,2,1,0. By using this, rather than straight binary (8,4,2,1,0), you get the following rule: Each group of 5 will have 2 tall bars and 3 short bars. This provides kindof an error check against misprinted bars.
Example, to represent a one: ... would be (1 times 1 plus 1 times 0). Here are the digits 1-9: ... ..|.| ... .|..| .|.|. ... |...| |..|. |.|..
For zero(0) this set of bars is used: ... (it adds up to 11, but the barcode readers know that this means zero, and it's the only other way to use 2 tall bars. The last digit represented by the last set of 5-bars in the string of digits, is a checksum digit. All the digits are added up, and then the checksum digit is the number required to make the total sum of digits equal a multiple of 10. So if the digits add up to 32, the checksum digit will be an 8.
Chat with our AI personalities