During the mashing of the grains, the amylase found in the barley is used to break down unfermentable starch into fermentable glucose. The goal is to break down as much of the starch as possible.
Starch comes in two different forms, amylose and amylopectin. They are both polymers of glucose. Amylose is a linear polymer, and amylopectin is a branched polymer. There is usually more amylopectin in a given sample starch, but it is the amylose that can be used to identify the mashing progress.
A common and simple test for the presence of starch is the iodine test. A solution of iodine (I2) and iodide (I-1 from something like potassium iodide, KI) is added to the sample. The iodine/iodide solution is reddish, but in the presence of amylose it turns dark blue (almost black).
First of all, iodine (I2) is not terribly soluble in water. The addition of iodide (I-1) makes it soluble by forming an I3-1 complex ion.
Amylose adopts a coiled or helix shape. When I3-1 is added it gets trapped in the coils of amylose. The iodine atoms trapped in the coils can be in the form of I3-1 or I5-1 or more iodine atoms (I'm not sure and I don't know if anyone is). The resulting interaction between the amylose and the iodide complex results in a shift of the light being absorbed by the iodide complex. This happens because there is transfer of charge to the starch molecule. This affects the energy spacing of the electrons in the iodine.
The result is a complex that does not absorb light in the blue region of the visible spectrum.