In this document I will go into some detail about how an ISBN barcode works, what the black and white stripes mean.
First I'll choose a book and show you its ISBN and its ISBN barcode.
I've chosen a book called “Beyond Bullet Points”, it's by Cliff Atkinson and it's published by Microsoft Press.
Its 13 character ISBN is 978-0-7356-2387-3. In an ISBN barcode, we are just interested in the numbers. The hyphens aren't encoded, so we'll just refer to the ISBN number from here as 9780735623873.
Here's a photograph of our book's ISBN barcode from the back cover.
Actually, there are two barcodes there. The ISBN barcode is on the left, while on the right is an extra barcode which is called an ISBN Addon5. For the time being we are just interested in the ISBN barcode on the left.
First we are going to be an ISBN generator and build the ISBN barcode from the ISBN number 9780735623873. In order to do that, there are some basic principles to get to grips with.
Like most things to do with computers, everything eventually comes down to zeros and ones. The ISBN barcode is no exception. The black bars and the white spaces between the bars translate to a combination of zeros and ones. In what follows, instead of talking about black bars and white spaces, I'll just call them black bars and white bars.
You will notice that the black and white bars are of varying widths. There are four different widths for both black and white.
Principle 1: The thinnest bar is called the module or x-width.
The next thickest is twice the thickness of the first - two modules. The width of the third thickest is three modules, and the widest is four modules.
The whole ISBN barcode is a set number of modules wide. That number turns out to be 95.
Principle 2: A thin black bar is a one (1) and a thin white bar is a zero (0).
Every edition of a book has a unique number, but every ISBN barcode has the same basic framework. This is illustrated below.
Those three groups of bars create the framework for the rest of the ISBN barcode. They are not part of the ISBN number, but as far as the workings of the ISBN barcode system are concerned they are the fundamental structure of the barcode and provide the container, if you like, for the ISBN number itself.
As part of the ISBN barcode, each of the bars of the framework have the values noted in Principle 2. The left and right parts are both a black bar, a white bar and a black bar, so both have binary values of 101. The centre bars, while they look the same as the outer bars, are in fact white, black, white, black and white, which is 01010. You need to be aware that there is a white bar to left and a white bar to the right of what you can see. All of the bars so far described are bars of the thinnest variety, so are one module wide. That's three modules on the left, five in the middle and three on the right.
That means there is room left for 84 modules – 42 in the first large space and 42 in the second. There are six ISBN digits in the first space and six in the second. Each ISBN digit needs 7 modules of space in which to encode it. 7 modules each for 12 digits uses up exactly the 84 modules of space. But wait! The ISBN number comprises 13 digits, and we only have room for 12. The reason for this is that the first of the thirteen characters of the ISBN number is not encoded in the same way as the following twelve. It doesn't actually appear as black and white bars - it's encoded in a different way. We'll see how that happens in a while. First I will explain how the final 6 characters of the ISBN number are encoded – they're the easiest to understand and that will give us a good foundation on which to understand the slightly more complex encoding of the first 7 characters.
If you guessed that the final six characters are encoded into the space between the middle bars and the final bars, then you guessed correctly. Below is a table that shows the encoding regime for the final 6 characters.
|ISBN Barcode - Encoding For The Final 6 Characters|
|ISBN Character||Binary Code|
Each binary digit (each 0 and 1) creates a one module width stripe in the ISBN barcode. Each 0 makes the thinnest white bar and each 1 makes the thinnest black bar. Two or more one module bars of the same colour right next to each other just create a thicker bar, of two or more modules wide.
I want you to notice the following important details about the encoding for the final 6 ISBN number characters.
So let's take the final 6 digits of our ISBN number and encode them using the table.
Our 6 digits are 623873
6 is 1010000 2 is 1101100 3 is 1000010 8 is 1001000 7 is 1000100 3 is 1000010
Join them all together one after the other and we get:
When we turn our 1s into black blobs and our 0s into white blobs we get:
Now if we show that again as proper barcode bars it looks as we might expect.
When we fit that into the ISBN barcode framework, this is what it looks like.
That wasn't too difficult, was it? We're nearly done!
Just the first part to do. But that is a bit more difficult. We need two different encoding schemes for the characters in the first part of the ISBN barcode. Lets look at those. We call them Scheme A and Scheme B.
|ISBN Barcode - Encoding Characters 2 to 7|
|ISBN Character||Binary Code - Scheme A||Binary Code - Scheme B|
If you compare the Scheme A binary codes with the codes from the previous table for the final six characters that we have just completed, you will notice that each 1 is now a 0 and each 0 is now a 1. Similarly, if you compare Scheme B binary codes with the codes from the previous table for the final six characters, you will notice that they are flipped, right to left.
Each remaining character in the ISBN number, apart from the first one, is encoded from one of the two schemes, A or B. Which scheme to use for which character is determined by a further table. It is the choice of which scheme is used for each of characters 2 to 7 that encodes the value of the first character of an ISBN barcode. The first character in an ISBN number is always a 9. As the first character is always a 9, the encoding for characters 2 to 7 always follows the scheme in the following table.
|ISBN Barcode - Encoding Schemes for Characters 2 to 7 Where Character 1 is a 9|
|Scheme for char 2||Scheme for char 3||Scheme for char 4||Scheme for char 5||Scheme for char 6||Scheme for char7|
So let's take characters 2 to 7 of our ISBN number and encode them with the information that we now have.
Our six digits are 780735.
7 (character 2) uses Scheme A so its binary code is 0111011.
8 (character 3) uses Scheme B so its binary code is 0001001. 0 (character 4) uses Scheme B so its binary code is 0100111. 7 (character 5) uses Scheme A so its binary code is 0111011. 3 (character 6) uses Scheme B so its binary code is 0100001. 5 (character 7) uses Scheme A so its binary code is 0110001.
Join them all together in order to make:
Making the 0s white blobs and the 1s black blobs gives the pattern:
That pattern as bar code bars looks like this:
You will notice that this part of The ISBN barcode begins with a white bar, even though it won't show up here without a black bar to the left of it. So lets see these bars in the context of the ISBN barcode framework.
Now there is just the human readable numbers to add to the bottom of the ISBN barcode and it's all done.
There are some specifications about sizes that you need to be aware of.
Standard dimensions are given for various ISBN barcode factors. There should be a quiet zone or light margin with nothing printed in it to the left and right of the ISBN barcode. This is so that the barcode scanner and the barcode software is able to determine where the ISBN barcode begins and ends.
The dimensions shown below are for a nominal size of ISBN barcode. This is referred to as the 100% magnification. The nominal module or x-width size is 0.33 millimetres. Instances of the ISBN barcode may be used down to 80% and up to 200% of the nominal size.
Now we are going to take our ISBN barcode and be an ISBN barcode scanner and read the ISBN barcode, scanning the system of black and white bars and decoding them into the valid ISBN number.
First the ISBN barcode scanner needs to find the left guard pattern of black-white-black (101). This will enable the ISBN barcode software to find out where the pattern of bars will begin and to determine the width of the basic unit width, know as the module or x-width. All of the guard bars, both black and white, are one module wide.
The left guard bars are a one module width black bar, followed by a one module width white bar (effectively the background colour of the ISBN barcode), and finishing with a second one module width black bar. Because the left guard finishes with a black bar, then the following section has to begin with a white bar.
Having read the left guard pattern, the ISBN barcode scanner now reads the first 24 alternating bars – 12 pairs alternating white/black.
In reading this section of 24 bars, we are reading the encoded data for 6 digits of the ISBN number that this ISBN barcode represents. Each of those six in this section is encoded as four bars – white-black-white-black. Each bar can be of varying width. At this stage of the scanning of the ISBN barcode, just be aware of those basic facts. We will learn more about the widths of the bars when we come to decode the bars. At the moment our barcode scanner is recording what it reads for later processing - essentially the colour and width of the bars.
Having read and stored the data for the first 24 data bars, the ISBN scanner expects to find the middle guard bars. The middle guard bars at first sight seem to be the same as the left guard bars, but that's not quite right. The left guard bars, you will remember were black-white-black (or 101). Because the data bars that our ISBN scanner have just read end with a black bar, then the middle guard bars must start with a white bar. The middle guard bars are defined to be white-black-white-black-white (01010).
The middle guard bars end with a white bar, making the next section, which is a second set of 24 alternating bars, start with black and end with white. This being the opposite of the first set of 24 data bars, which started with white and ended with black. Our ISBN barcode scanner reads and stores the second set of 24 bars, as it did the first.
Having done that, our ISBN scanner then expects to find the right guard bar, which like the left guard bars, are a sequence of three single module bars of black-white-black. This acts as a confirmation to the barcode scanner and the barcode software that the ISBN barcode has been read successfully.
Our ISBN barcode scanner, having successfully negotiated the ISBN barcode and stored the data that encodes the ISBN number, now has to decode that data.
The ISBN barcode software refers to the data saved earlier from the scan. It has two blocks of 24 bars. We will take each block separately, because they are decoded in different ways. If you have read the earlier explanation of how the ISBN barcode is formed, you will already have a good idea how this will work, because you understand how the encoding process dealt with the same data.
Let's take the first block of 24 bars that we read and analyse their structure. Here's how our ISBN barcode scanner read them. Delineating lines have been added to show the 6 digits, each with 4 bars of white-black-white-black.
You will be correct in thinking that the key to decoding these bars is in the varying width of the bars.
In order to show the different widths clearly, we shall now see how the same data looks when overwritten with a grid where each bar is “split” into its component modules.
A module, you will remember, is the fundamental unit of the ISBN barcode. Here you will be able to see that each four bars, and therefore each ISBN digit encoded, is 7 modules wide. In order to decode the data, we translate the colour of each module to its binary digit. Each white module is a zero (0) and each black module is a one (1).
The first ISBN digit is white, black, black, black, white, black, black which equals 0111011.
The second ISBN digit is 0001001.
The third is 0100111. The fourth is 0111011. The fifth is 0100001. The sixth is 0110001.
You may think that the six ISBN digits that we are decoding are the first six in the ISBN number. That is not so. These six digits are digits 2 to 7 of the ISBN number. The first digit of the ISBN number is cleverly encoded in the way those following six are encoded.
A Brief Aside As it happens, we don't really need to decode the first digit of an ISBN number, because it will always be a 9. From the 1st of January 2007 all new ISBN numbers conform to a wider system of product numbering known as EAN, and all ISBN barcodes also conform to the same international product numbering system. That standard gives the first two or three digits if the 13-digit product code to the country of origin of the item. In the case of books and their ISBN numbers, they are all deemed to come from the imaginary region known as Bookland. Bookland has the country designators 978 and 979. You may sometimes see a 13-digit ISBN number referred to as a Bookland ISBN. For more details see the 13-digit ISBN numbers page. For details of the older ISBN standard see the 10-digit ISBN numbers page. For details of the wider system of product numbering see the EAN page.
Because ISBN numbers conform to the wider EAN standard, we shall carry out the decoding as if we were decoding a general 13-digit EAN.
In order to decode digits 2 to 7 from the data that we already have, and from that to determine the first digit of the ISBN number we need to look up the binary codes in a table.
|ISBN Barcode - Decoding Characters 2 to 7|
|Binary Code||ISBN Character||Encoding Scheme|
Let's remind ourselves of the binary codes of ISBN digits 2 to 7.
0111011 0001001 0100111 0111011 0100001 0110001
Looking up the first, 0111011, we see it is 7 with encoding scheme A
0001001 is 8 with encoding scheme B 0100111 is 0 with encoding scheme B 0111011 is 7 with encoding scheme A 0100001 is 3 with encoding scheme B 0110001 is 5 with encoding scheme A
Therefore, digits 2 to 7 of our ISBN number are 780735
The first digit is encoded in the encoding scheme order used for digits 2 to 7. The order that we have just found is ABBABA. From the table below, we can determine the first digit of our ISBN number.
|ISBN Barcode - Decoding the First Character|
|Encoding Scheme||ISBN Character|
So ABBABA is 9. This confirms that our ISBN number begins with a 9. So the first 7 digits of our ISBN number are 9780735.
Now we can use the data that our ISBN barcode scanner read for the last six digits of the ISBN barcode. It has already been overlaid with the grid that splits the data up into ISBN digits and the digits into individual modules.
You will notice that the encoded form of each ISBN digit is black-white-black-white bars of varying width, and that each starts with a black bar and ends with a white one. Like digits 2 to 7, each of digits 8 to 13 is six modules in width.
The digital representations of characters 8 to 13 of our ISBN number are:
1010000 1101100 1000010 1001000 1000100 1000010
To decode these digital codes needs another table.
|ISBN Barcode - Decoding Characters 8 to 13|
|Binary Code||ISBN Character|
In just the same way that we looked up digits 2 to 7, we lookup digits 8 to 13 of our ISBN number.
1010000 = 6 1101100 = 2 1000010 = 3 1001000 = 8 1000100 = 7 1000010 = 3
There we have it. The final 6 digits of our ISBN number are 623873. Appending them to the first seven digits decoded earlier we have our complete ISBN number. It is (roll of drums please, maestro!) 9780735623873.
But wait, there's one more thing to do. The final digit of an ISBN number is an error check digit. Its function is to help detect any errors in transmission of the complete ISBN number. When the ISBN number was issued by the issuing authority, the check digit was created by a calculation performed on the first 12 digits. We can repeat that calculation and confirm that the check digit that we have decoded from the ISBN barcode is the same as the one we calculate.
The calculation involves modulus arithmetic and is not difficult. We take the first twelve numbers of the ISBN number and extract the second, fourth, sixth, eighth, tenth and twelfth and add them together.
7 + 0 + 3 + 6 + 3 + 7 = 26
Multiply the result by 3
26 * 3 = 78
Add that result to the first, third, fifth, seventh, ninth and eleventh of the ISBN number's digits that we didn't use in the first part of the calculation.
78 + 9 + 8 + 7 + 5 + 2 + 8 = 117
The check digit is the number that must be added to the result (117) to get to the next exact multiple of 10 (in this case 120). So the check digit is 120 – 117.
120 – 117 = 3
We calculated the check digit is 3 and the check digit that we decoded from the ISBN barcode was 3. They agree, so we can have some confidence that we have completed the process of decoding an ISBN barcode successfully!