Above is the standard book barcode format. It is created using the ISBN which is also needed to publish a book. See my article How to get an ISBN. The ISBN forms the bars which are read by the barcode machine identifying the book. The smaller barcode on the right is encrypted with the price which allows you to set a price for all retailers to sell your book for.
There are many ways to get a barcode. Some online self publishing sites will provide you with one when you publish with them for example CreateSpace provide barcodes. However if you are doing the printing yourself then you will need to create one yourself. Many of the ISBN distributors can also sell you a barcode with your number however this will cost you. The best option I found was http://www.tux.org/ where you can create a barcode for free and download it in either .pdf or .eps format. It also lets you set the price for the price barcode to the right.
Book barcodes are created in EAN-13 format. It is important to get this right as bookstores barcode machines will not necessarily read other barcodes. Make sure you test your barcode before printing your books. Simply print it out on paper and go to your local bookstore and get them to test it on their barcode scanner. This is also a good idea with the test print of the final book as this will make sure the print quality is correct and the stock is suitable. Barcodes are a very important part of your book, without them you can't really sell it. Make sure they are correct before you go to print.
Allow a lot of space around the barcode especially against the spine. The barcode must sit in the bottom right corner of the back cover. Use black on a white background if you don’t know what you’re doing. Barcode readers will only pick up certain colours.