We all love clean clothes: their smell, their look, their feel. We use copious amounts of detergent each year. However, aside from watching commercial dramatizations, we pay little attention to how stains are removed. To understand how detergents work, you must first understand the factors that come into play while washing. You have the dirty shirt and a stain that's made up of a "compound" that chemically bonds itself to the fibers of the clothing. Beyond that, the water that you wash your clothes with has charged metal particles like sodium, calcium and iron, floating around your water, which can make your cleaning agent less effective.
Detergent should not be seen as one substance, but its own "ecosystem" that affects the space where the water touches the clothing, to effectively remove stains. Most detergents have seven different components working together. Surfactants (short for "surface actants") act as "emissaries" between the water and stain areas, easing the tension between the two, eventually enveloping and dissolving the stain. Enzymes break down stain molecules into smaller components. Builders bond with the metals in the water, so that the surfactants can work efficiently. Polymers catch dirt in the water, making sure it doesn't settle back on the clothing. Lastly, bleach destroys molecules that produce color, optical enhancers absorb UV light and release the light that is the color of the shirt (to brighten), and lye or ammonia keep the pH balance steady (how acidic or basic the detergent is in water).
Just like Eastern philosophy, detergents are all about balance. Finding the right pH and the amount of surfactants or enzymes in the product all play a key role in its effectiveness. Too little surfactants won't get out the stain, and too many will leave a residue on your clothing. Although reading the washing directions on your clothing labels and the directions on the detergent bottle is common sense, it's important to help set the right balance for the pieces of clothing. It might be hard to gauge what percentage of a specific chemical is being used for the cleaning, so I would suggest improvising and adjusting the water amount, water temperature and detergent concentration, depending on your results for different loads.
You've all probably heard about phosphate versus non-phosphate detergent. Both can be used in the same way. Phosphate, a chemical that is sometimes used as a surfactant, is one of the key ingredients to life and is non-toxic. However, the problem is that when the phosphate enters the outside world it likes to promote life ― sewer and river life. It helps cells, like blue-green algae, grow exponentially, killing off fish populations in rivers. To avoid this, many companies now use a synthetic surfactant called zeolite, which is not as effective without the help of other chemicals. Phosphorous can be recycled, but a very small percentage is removed from sewage treatment (although some countries in Europe have been working on this). If you're environmentally conscious, you should steer clear of them.