Stearic Acid is a typical example of a fatty acid, which are essentially long hydrocarbon chains containing a carboxyl group at one end and a methyl group at the other. The chain lengths can vary from 3 (propionic acid) to 24 (lignoceric acid) but the majority of fatty acids found in hydrogenated vegetable or animal oils are around C16-C20 in length. Stearic acid is a saturated acid, since there are no double bonds between neighbouring carbon atoms. This means that the hydrocarbon chain is flexible and can roll up into a ball or stetch out into a long zig-zag.
It is made by extraction from tallow, which is the mixture of fats that are obtained by steam treating cow fat. Tallow contains tristearin (which is just 3 stearic acid molecules joined to one glycerol molecule, shown in blue in the figure), which, after heating with sodium hydoxide yields sodium stearate.
Sodium stearate is a typical example of a detergent or soap, since it contains a long hydrocarbon 'tail' (magenta) and a carboxylic acid 'head' group (blue).
The molecule gets over the problem that "oil and water don't mix" by having a molecule with 2 parts - an oily part and an ionic part. The tail is basically an alkane, and so readily dissolves in fat, oil and grease, but not in water. Thus the tail is said to be hydrophobic (water-hating). The head-group however is polar, and so easily dissolves in water (hydrophilic - water-loving) and will not dissolve in oil or grease. Thus when added to water containing dirt, oil or fat droplets (e.g. when doing the washing up, at bathtime, or the laundry, etc), the tail avoids contact with the water by burying itself into the oil droplets, leaving the head groups sticking out into the water, as they prefer. Thus the oil and dirt are dragged off the dirty objects (dishes, clothes or people!) collected together into clumps and washed down the drain.
Sodium stearate is not the only fatty acid to be used in soaps. Sodium laurate (the salt of lauric acid which is a C11 fatty acid extracted from coconut oil) is often added. Potassium salts of fatty acids are also used, in combination with excess stearic acid, to give a slow-drying lather for shaving soap.
Natural bacteria can metabolize soaps, and this process is most rapid when there are no branches in the hydrocarbon tail of the soap molecule. Since the naturally occurring fatty acids are all straight-chained, soaps derived from natural fats (like sodium stearate and laurate) are biodegradable. However, in 1933 the first synthetic detergents were marketed, with the advantage that they did not form the hard 'scum' that often results when soap is used in hard water regions. (This scum is actually the insoluble calcium and magnesium salts of the fatty acid, e.g. calcium stearate.) The first detergents were alkylbenzenesulfonates: like soaps they had a polar head and a large hydrocarbon tail, but the tail was branched.
Sodium Alkylbenzene Sulphonate
That meant that these early detergents were not easily biodegradable, and since the bacteria which operated in sewage plants could not metabolize them they were passed into the waterways with the treated sewage, often appearing as unsightly foam or suds on the surface of lakes and rivers. Faced with this problem, in 1965, the detergent industry introduced linear alkanesulfonate detergents (such as the one shown in the figure), which, being straight-chained compounds, were biodegradable.