How Can Black Lines on a Barcode Contain a Number?
A barcode does not store information in the black ink alone. Its message is created by the changing widths and positions of both black bars and white spaces.
When a scanner shines light across the symbol, pale areas return more light while dark bars absorb more. A sensor records these alternating reflections as an electrical pattern.
The common Universal Product Code divides that pattern into groups representing digits. Each digit corresponds to a particular arrangement of bars and spaces with specific widths. Guard patterns at the beginning, middle, and end help the scanner recognize the structure and determine how the code is oriented.
Digits on the left and right sides use related but different patterns. This allows a scanner to read the symbol even when the product passes across it upside down. The final digit serves as a check digit, calculated from the others. If the scanned pattern does not produce the expected result, the system knows that a reading error probably occurred.
The barcode usually does not contain the product's price or complete description. It carries an identification number. The store's computer uses that number to find the corresponding record in a database, where the current price and inventory information are stored. This allows a shop to change a price without printing a new code on every package.
The first product scanned with the modern commercial system was a pack of chewing gum in an Ohio supermarket in 1974. The gum itself was ordinary, but the scan demonstrated a new connection between printed packaging and computerized inventory.
A barcode is therefore a simple optical language. Light turns the spacing of ink into digits, and those digits open a much larger record stored elsewhere.
Source: Barcode, Encyclopedia of Computer Science - The Bar Code Book, Roger Palmer

Amphiprion ocellaris (Clown anemonefish)
Source: By Nick Hobgood