Intelligent Mail Barcode Decoder

Please enter your barcode below, using the following characters:
A = Ascending bar, D = Descending bar, F = Full bar, T or S = Track (short) bar
ZIP Code: -
Delivery Point:
Barcode ID:
Service Type:
Mailer ID:
Serial Number:
Delivery point is "usually" the last two digits of the street address.

Sample Data

Here are some sample barcodes from the specification document. They all encode Barcode ID = 01, Service Type = 234, Mailer ID = 567094, Serial Number = 987654321.
  • Remarks

    The Intelligent Mail Barcode (or IMB) is used by the United States Postal Service. It has a fixed length of 65 bars. It is height-modulated (the vertical bars are different lengths) and 4-state (there are four different kinds of bars). The encoding is highly opaque - it would be very difficult to glean any information from this type of barcode just by looking it. Notice how many bars change if you change one digit in the decoded information and click Encode.
    An error-detecting code is embedded in the symbol, so that damaged or incorrectly scanned barcodes can be detected. The decoder above uses this property to correct small errors in the barcode entered.

    More Information

    Overview of the Encoding Process

    This is a high-level overview of how IMB barcodes are encoded. Please refer to the specification for full details.
    1. Concatenate all of the input fields (ZIP Code, Delivery Point, Barcode ID, etc.) into one long number with up to 31 digits. Convert this number from decimal (base 10) to binary (base 2). (There's some additional monkey business, but that's the basic idea.) The result will be up to 102 bits long.
    2. Generate an 11-bit Frame Check Sequence (FCS) of this value, for detection of errors. The FCS is actually a Cyclic Redundancy Check.
    3. Convert the binary data to base 1365, resulting in 10 "codewords". Actually, the low codeword is calculated differently, so it is always less than 636.
    4. Multiply the low codeword by 2 (this is to detect upside-down barcodes; read on to see how).
    5. If the high bit of the FCS is set, add 659 to the high codeword. The result is always less than 1318.
    6. Encode each codeword into a 13-bit "character". This is simply done by looking it up in a table; the table makes up the bulk of the specification document. Every valid character in the table has exactly 2 or 5 one-bits.
    7. For each character, if the corresponding bit of the FCS is set, flip all the bits in the character. The resulting modified characters have either 2, 5, 8, or 11 one-bits.
    8. Break up the 10 characters into 130 bits and scramble them according to another table. Each bit becomes either the top or bottom part of one of the 65 bars in the code.
    It's complicated, isn't it?
    Detection of upside-down barcodes works as follows. The table used in step 6 is ordered in a particular way: characters that are palindromes are placed towards the end of the table, and each non-palindrome is listed next to its reversed counterpart. This means that reversing the bits in a 13-bit character adds or subtracts one from the corresponding codeword value, if the codeword appears early enough in the table. The scrambled order of step 8 was chosen so that turning the barcode upside-down reverses the bits in the low character. Thus, when an upside-down barcode is read and decoded, the low codeword will be odd.

    Error Correction

    The error correction feature in this decoder works by finding 13-bit characters that have an incorrect number of one-bits. It assumes that each character has only one bit error, and finds all the valid characters that are one bit-flip away (there may be up to 12 of them). Then it tries each possible character by decoding the barcode and seeing if the FCS matches. It is likely that only one will, and this is reported as the suggested replacement.
    Multiple characters may have errors (changing one bar potentially changes two characters, after all). In this case, the decoder tries all possible combinations of valid replacement characters to find one that works. However, if many characters have errors, the computation time grows exponentially, and it becomes likely that some of the incorrect decodings will have the correct FCS "by accident". For this reason, there's an arbitrary limit of 1000 possible combinations, and the decoder will declare a barcode "too broken to fix" and give up if this is exceeded.

    Download the Decoder

    Here is the Javascript code for the IMB barcode decoder. You can download it and do whatever you like with it. Use the HTML file below to run it locally on your computer - just save both files in the same place.
    File Size: 17 kb
    File Type: js
    Download File

    File Size: 2 kb
    File Type: html
    Download File