To know how barcode scanners read barcodes, first of all, we must know the optical properties of barcodes.
The bars of barcodes are composited by different widths, White margins can reflect visible light of various wavelengths, and black bars can absorb visible light of various wavelengths.
Simply put , there are three components：the “illuminator”, emits red light towards to the barcodes. And the “sensor”, senses the different reflected visible light from the barcodes, and the “decoder”, converts these reflected lights into electronic signals and become digital codes as ouput. This is how barcode readers work.