Don't trust the expiration dates on supermarket coffee. If you're unsure of whether you're really getting fresh-roasted coffee for the best possible cup, use a zipper-lock bag for an overnight test.
Photo by pokpok313.
If you don't want your coffee to taste like the last pot at an all-night diner, you can take a lot of steps to brew the best cup without spending a bundle. Unless you're roasting yourself though, you're at the mercy of whoever's selling you your beans. If you're unsure of the quality, or how long you've had them stashed in your cupboard, Cook's Illustrated has a good test:
To check if your beans are fresh, scoop 1/2 cup into a zipper-lock bag and press out all the air, then seal the bag and leave it overnight. If the beans are within seven to 10 days of roasting, they will make the bag puff up from the carbon dioxide that they release. If the bag remains flat, then the beans are not producing gas — a sign they've passed the point of peak freshness.
eHow picked up on the overnight bag test, and has a few additional tips on bean longevity as well.