Taking a swig from a skunky beer leads to an unpleasant surprise, but you don't have to take a gamble every time you crack open a bottle. A beer's expiration date depends on a number of factors, such as the way it's packaged and stored, as well as what type of brew it is. You can't prevent your beer from aging, but you can make it happen more slowly.
Depends on the Beer
While the length of time it takes for your beer to go bad can vary, if you keep it in a cool, dark place, beer generally keeps for about a year before you notice a bad taste. Some beers go bad noticeably faster than others, however. For example, a hoppy IPA will start turning skunky before a light beer does -- this is because stale flavor is related to chemical reactions in the hops over time. A beer with a higher concentration of hops, like an IPA, will consequently start breaking down faster.
Chilled beer lasts longer than beer that's left out at room temperature, but it isn't only a matter of temperature. UV light affects how long a beer lasts before it goes bad -- the light breaks down the beer's hops, making it stale. This is why some beers come packaged in green or amber bottles instead of clear glass. You shouldn't buy beers that have been displayed in a store window, for example, because they won't last as long as those shielded from the light.
Timing and Temperature
Beer that is stored in a cooler or refrigerator typically tastes fresher than if it were on a store shelf. This is because temperature can quickly compromise the beer's freshness. In fact, it may take as little as five days for the taste of your beer to noticeably change -- this doesn't necessarily mean it has gone bad, but it indicates that it will eventually go bad faster than if it had been refrigerated. If you plan on storing your beer for several months, keep it in a cool location.
Aged by Design
Some beers are deliberately exposed to warm temperatures as part of their brewing process -- essentially, continuing to ferment after they leave the brewery. For example, European beers -- many of which are meant to be consumed warm -- may be imported without refrigeration, giving them time to age and develop new flavors before they reach American distributors. This goes to show that not only are there no universal expiration dates, but also that a little aging isn't necessarily a bad thing.