Shelf life is length of time that food can be stored safely.  Food cannot be kept forever. After a certain time it will go bad.  After this time it is no longer safe to eat it.  Shelf life is also used for drugs, drinks and other things that can go bad.

In some countries, a best before, use by or freshness date must be put on packaged foods.

During this time, if the food is kept under proper conditions the quality of the food does not change.  Frozen food that does not remain frozen will go bad earlier, for example.  Most of these labels do not guarantee the safety of food.  They should only be used as a guide.

Shelf life 
Shelf life is different from expiration date.  Shelf life is linked to food quality, expiration date to food safety.  A product that has passed its shelf life might still be safe, but quality is no longer guaranteed.  In most food stores, shelf life is controlled by using stock rotation.  This means moving products with the earliest sell by date to the front of the shelf, so that most shoppers will pick them up first and take them out of the store.  This is important, as stores can be fined for selling out of date products.  Most shops, if not all, will have to mark such products down as wasted, leading to a loss of profit.

Shelf life is can be changed by many things: exposure to light and heat, transmission of gases (including humidity), mechanical stresses, and contamination by things such as micro-organisms.

Mathematically, product quality is often modelled using only one parameter, for example the concetration of a chemical substance, a microbiological index, or a physical parameter. Sometimes, the parameter picked is irrelevant.

The shelf life is an important factor to health. Bacteria are everywhere, and foods left unused too long will often get large amounts of bacterial living in them. It may be dangerous to eat them and lead to food poisoning. The shelf life itself cannot always be trusted to tell how safe it is to eat a certain item of food. For example, pasteurized milk can remain fresh for five days after its sell-by date if it is refrigerated properly. In contrast, if milk already has harmful bacteria, the use-by dates do not matter.

For drugs the situation is different. If drugs are used within the expiration date, the manufacturer guarantees that they work as expected. After that date, they may still work, but only to a lesser extent. A rare exception is a case of renal tubular damage said to have been caused by out of date tetracycline. A study done by the U.S. Food and Drug Administration covered over 100 drugs, prescription and over-the-counter. The results showed that about 90% of them were safe and effective as far as 15 years past their expiration date. Joel Davis, a former FDA expiration-date compliance chief, said that with a handful of exceptions - notably nitroglycerin, insulin and some liquid antibiotics - most expired drugs are probably effective.

Preservatives and antioxidants may be put into some food and drug products to make their shelf life longer. Some companies use induction sealing and vacuum pouches to add to the shelf life of their products.

Some degradation factors can be controlled by provisions in the ed packaging. For example, the amber bottle used for many beers blocks damaging wavelengths of light. Transparent beer bottles do not. Packaging with barrier materials (e.g., (low moisture vapor transmission rate, etc.) extends the shelf life of some foods and pharmaceuticals.

Temperature control
Nearly all chemical reactions will occur (at various rates depending on the individual nature of the reaction) at common temperatures. Examples are the breakdown of many chemical explosives into more unstable compounds. Nitroglycerine is notorious. Old explosives are thus more dangerous (i.e., liable to be triggered to explode by very small disturbances, even trivial jiggling) than more recently manufactured explosives. Rubber products also degrade as sulphur bonds induced during vulcanization revert; this is why old rubber bands and other rubber products soften and get sticky as they age.

These breakdown processes usually happen more quickly at higher temperatures. The usually quoted rule of thumb is that chemical reactions double their rate for each temperature increase of 10 Celsius degrees (C°) because of activation energy barriers become more easily surmounted at higher temperatures. However, as with all rules of thumb, there are many caveats and assumptions. This particular one is most applicable to reactions with activation energy values around 50 kJ/mole; many of these are important at the usual temperatures we encounter. It is often applied in shelf life estimation, sometimes wrongly. There is a widespread impression. for instance in industry, that "triple time" can be simulated in practice by increasing the temperature by 15 C°, e.g. storing a product for one month at 35 °C simulates three months at 20 °C. There is enough variation that this practical rule cannot be routinely relied upon .

The same is true, to a point, of the chemical reactions of life. They are usually enzymatically catalyzed which changes reaction rates, but with constant catalytic action, the rule of thumb is still mostly applicable. In the particular case of bacteria and fungi, the reactions needed to feed and reproduce increase at higher temperatures, up to the point that the proteins and other compounds in their cells themselves begin to breakdown, or denature,  so quickly that they cannot be replaced. This is the reason high temperatures kill bacteria and other micro organisms; 'tissue' breakdown reactions reach such rates that they cannot be compensated for and the cell dies. On the other hand, 'elevated' temperatures short of these result in increased growth and reproduction; if the organism is harmful, perhaps to dangerous levels.

Just as temperature increase speeds up reactions, temperature decreases reduce them. Therefore, to make explosives stable for longer periods, or to keep rubber bands springy, or to force bacteria to slow down their growth, they can be cooled. This is the reason shelf life is generally extended by temperature control: (refrigeration, insulated shipping containers, controlled cold chain, etc.)  and the reason some medicines and foods must be refrigerated.

Best before
Best before is sometimes put on food and drink wrappers, followed by a date. It shows the date before which the supplier intended the food should be consumed. The term best before is also used to show the date by which the item will have outlived its shelf life, and is intended to ensure that customers will not unwittingly purchase or eat stale food. Sometimes the packaging process involves using pre-printed labels, making it impractical to write the best before date in a clearly visible location. In this case, a  term like best before see bottom or best before see lid might be printed on the label and the date marked in a different location as indicated.

Best Before is usually advisory and refers to the quality of the product, in contrast with Use By which indicates that the product is no longer safe to eat after the specified date.

Use by
Generally, foods that have a use by date written on the packaging must not be eaten after it has expired. This is because such foods usually go bad quickly and may be dangerous to eat. It is also important to follow storage instructions carefully for these foods (for example, product must be refrigerated).

Foods that have a best before date are usually safe to eat after the date has passed, although they are likely to have deteriorated either in flavour, texture, appearance or nutrition.

Bathroom products/toiletries usually state a time in months by which,  once the product is opened, they should be used. This is often indicated by a graphic of an open tub, with the number of months written inside (e.g., "12M" means use the product within 12 months of opening).

Open dating
Open Dating is the use of a date or code stamped on the package of a food product to help determine how long to display the product for sale. It is also helpful to the customer and ensures that the product is at its best quality when bought. An Open Date does not supersede a Use by date, which should still be followed.

Sell by / Display until
These dates are meant to help keep track of the stock in stores. Food that has passed its sell by or display until date, but is still within its use by / best before can still be eaten, if it has been stored correctly. It is common practice in large stores to throw away such food, as it makes the stock control process easier. It also reduces the risk of customers buying food without looking at the date, only to find out the next day that they cannot use it. Changing the posted date is illegal in many countries.

Most stores will rotate stock by moving the products with the earliest dates to the front of shelving units, which allows them to be sold first and saving them from having to be either marked down or thrown away, both of which contribute to a loss of profit.

Mark-downs
It is also common for food approaching the use by date to be marked down for quick sale, with greater reductions the closer to the use by date it gets.

Software Shelf Life
In a metaphorical sense, much software also has a shelf life. Most software products are released to market with defects, xecurity vulnerabilities, and design flaws. Over time, some of these are discovered and patches issued by the vendor (and possibly others, as in the open source environment) which fix bugs and add functionality. The result is that, after some time, the software application is rather different than it was at first release, even with the same version level. Since correct inclusion of patches at end user sites is spotty, the actual population of that software application in the field is quite varied; some will have patches 1 and 2, others 1, 2, and 3, some others none, in  all possible variations. This increases support difficulty. There have been a few attempts to address this. One commercial attempt is from Preemptive.

US Government Guidelines
The Food & Drug Administration, which controls packaged foods and drugs, only requires a use-by, or expiration, date on infant formula and some baby foods. That's because formula must contain a certain quantity of each nutrient that is described on the label. And if formula is stored too long, it loses its nutritional quality. It also separates or form lumps that will clog the bottle nipple. Except for infant formula and some baby foods, product dating is not required by federal regulations.

The Agriculture Dept., which controls fresh produce and meats, only requires labeling of the date when poultry is packed at the farm. However, many manufacturers are allowed to also add sell-by or use-by dates.

Example

Beer freshness date
A freshness date is the date used in the American brewing industry to indicate either the date the beer was bottled or the date before which the beer should be consumed.

Beer is does not keep forever. It can be affected by light, air, or the action of bacteria.  Although beer in the USA does not have to have a shelf life, freshness dates serve much the same purpose and are a marketing tool.

Beginnings of freshness dating 
The Boston Beer Company, maker of Samuel Adams, was among the first to start adding freshness dates to their product line in 1985. For ten years there was a slow growth in  brewers adding freshness dates to their beer. The practice rapidly grew in popularity after the Anheuser-Busch company's heavily marketed "Born-On dates" starting in 1996. Many other brewers have started adding freshness dates to their products, but there is no standard for what the date means.  For some companies, the date on the bottle or can will be the date that the beer was bottled; others have the date by which the beer should be consumed.

Beer processing 

Before a beer is bottled, it is processed to make its shelf life longer. This can change the beer's freshness date. It may be done in several ways, not all of which will be used by a particular brewery:

Pasteurisation is a process by which a liquid is heated for a brief time to kill microbes that may be in the liquid. Pasteurisation has also been used for many years to keep milk safe for drinking due to bacteria that may be present.
Sterile filtration, in which the beer is passed through a mechanical filtration system which removes anything larger than 0.5 micrometres.  This removes any yeast or hops that may still be in the beer which would continue to react with it.
Bottle conditioning allows yeasts to remain in the beer after it is bottled.  This helps prevent some oxidation of the beer.
Freshness longevity affects the time it takes a beer to become stale. Some of this depends on the type of beer ingredients included. If the beer has more hops and more alcohol than otherwise, it will stay fresh longer than those that are not as strong.

Other websites 
USDA - Food Product Dating and storage guidelines 
FDA - Food freshness and smart packaging 
How to store your food

References

 Labuza, T. P., and Szybist, L., "Open dating of Foods". 2001, Food and Nutrition Press, Trumbul CN 
 "Cold Chain Management", 2003, 2006,  
 "Freshness and Shelf Life of Foods", Hugo Weenen and Keith Cadwallader,  
 "Shelf-Life Evaluation of Foods", by C. M. Man, A. A. Jones,  
 "Stability and Shelf Life of Food", by David Kilcast, Persis Subramaniam 

Food and drink