Dyes usually go through some chemical change that binds them to a fabric's molecules. This is different from paints, which sit on the surface of cloth and do not go through a chemical change. Dyes can be applied to cloth by immersing it in a container of dye solution, or by painting the dye on with brushes or sponges.
Chlorine bleach is an example most people recognize.
When you spill bleach on clothing accidentally, a chemical reaction occurs that alters the dye molecule and changes the color of the cloth. When this is used deliberately, a pattern can be created on the fabric surface. There are many kinds of discharging agents, but they all do essentially the same thing. One approach involves the use of a fabric woven from two kinds of thread - one is plant fiber, or cellulose, and one is animal fiber, known as a protein fiber. Cotton, rayon and linen are cellulose fibers.