As most foods are edible for only a finite period of time, the discovery of ways to preserve food was essential for human survival.
Before Louis Pasteur demonstrated that ferments, molds, and putrefaction were caused by organisms already present in the environment, the actual reason food spoiled was not understood. Europeans thought that changes in food were spontaneous: maggots were generated of their own accord out of old meat. Now that we know that microorganisms are the main cause of food spoilage, modern food preservation techniques work to either slow down the activity of these microbes or kill them altogether.
Probably the oldest method of food preservation is cooking, but it doesn't keep food safe for very long.
More effective for long-term storage is drying, and it has been used for centuries to preserve fruits, grains, vegetables, fish, and meat. Initially foods were most likely sun-dried or dried over a fire; smoking coats food with a protective layer of smoke and also imparts a characteristic flavour. The application of heat to a food is a variation on drying; this includes parching, used for grains like oatmeal or corn, and more recent processes like pasteurization and freeze drying.
Adding salt or sugar to foods can preserve them, and was used from ancient times in addition to, and in combination with, drying and smoking. In fact, salt and sugar were among the first preservatives ever used.
Pickling, an ancient technique, involves immersing a food in vinegar, itself the product of a preservation technique, fermentation. Fermentation uses the action of yeast to make alcohol, a good preservative because it kills bacteria: fruit placed in brandy will keep almost indefinitely.
Milk can be preserved by letting it sit out at room temperature; naturally occurring enzymes cause it to sour, yielding sour cream. (This doesn't work with pasteurized milk, though.) Milk can also be processed with the addition of rennet to make cheese.
Another old food preservation technique hinges on excluding air from around a food; this can be accomplished by pouring oil over it, coating it with fat or wax, or burying it in earth or sand (thousand year eggs, anyone?).
Canning was discovered in the early nineteenth century and helped make it possible to preserve fruits and vegetables for long periods of time. The food can be canned into metal containers, glass jars, or (more recently) flexible retort pouches; the important thing is to have an airtight seal and a high enough heat to completely kill the bacteria in the food.
The development of reliable refrigeration and freezing helped to preserve many foods for longer periods of time, though because they just slow down bacterial growth, they don't keep foods edible forever.
Today a great deal of processed food is preserved with food additives with menacing chemical names; see food additive for a partial list. A controversial new technique is irradiation; many people don't trust irradiation and fear that health hazards will be discovered later, but it has been approved by the Food and Drug Administration and the World Health Organization.