The number codes are encoded in two ways. The length of the bars and spaces determine the digit. Bar and space lengths are always multiples of 1,2,3 or 4 of the guard bar width. The total length of one character is 7 of these units. An interesting thing to note is the fact that you can scan a barcode either way.
Software can determine the correct order by looking ordering of the bars on the barcode.
The check digit is simply the remainder formed by the division in step 3. The encodings of characters and the design of the integrity check is to minimize misreadings. Erroneous readings should have a very small likelihood of passing the integrity check.