No one knows when the first soap was cooked up, but detergents are about a century old. Both come in wide varieties, but soaps and detergents are prepared using different methods and ingredients.
Soaps and detergents contain "surfactants"---compounds with molecules that line up around water to break the "surface tension" that holds it together in drops. They contain a combination of fats (or triglycerides) and alkali that create molecules with two unique chemical ends. One end, the "hydrophilic" end, is attracted to water, and the other, the "hydrophobic" end, is repelled by water but attracted to grease and oil. The hydrophobic ends bond with dirt, and the hydrophilic ends line up around them, encapsulating dirt and grease with a layer of molecules that will allow the dirt to float through the water and ride it down the drain. Surfactants can be anionic (negatively charged) or nonionic (no charge). Soap, the original surfactant compound, was made with fats such as lard and alkali from wood ashes or lye. Today a wide variety of organic and petroleum-based fatty acids are used, and sodium or potassium hydroxides have replaced wood ash or lye in commercially prepared soaps and detergents.
Soap is made two ways. The first, called "saponification," involves cooking fats and adding alkali to the mix at the end to form soap and two byproducts, water and glycerin. The second, called hydrolization, splits the fats and oils into fatty acids and glycerin using steam under pressure. It distills the acids and neutralizes them with alkali. Homemade soap hobbyists make five or six bars of soap using a pound of animal or vegetable oils, two ounces of lye (or other alkali) and about a cup of water. The oils are melted while the akali is added to the water and heated to approximately 110 degrees Fahrenheit. The lye water is added gradually to the cooled oils. The mixture gradually is simmered and re-simmered until a gelatinous substance called "trace" is formed. The trace is poured into molds and must age for several weeks to cure completely.
During the past century, the shortage of animal and vegetable fats during World War I and World War II led to the development of detergents, multiple-surfactant, hydrocarbon-based cleaners. Detergents, unlike soap, depend on chemical reactions for their formation. Petroleum-based oils (including "oleo," a compound used to make a replacement for butter) are combined with chemicals such as sulfuric acid, sulfur trioxide or ethylene oxide to form a fatty acid, which is combined with an alkali to form yet another molecule, an anionic surfactant. A second type of process converts a hydrocarbon into a fatty alcohol that then combines with another chemical such as ethylene dioxide to form a nonionic surfactant. Homemade detergents are made by combining a bar of laundry soap such as Fels Naptha or Zote (both of which contain petroleum distillates) with a pound each of washing soda (sodium carbonate) and borax (Sodium borate decahydrate). The combination can be powdered in a blender or the soap can be liquefied with water over heat; then the soda and borax are added to make a liquid.