Spices and herbs contain aromatic substances called essential oils, which are responsible for the aroma and much of the flavor. Try to buy your spices and herbs in the whole form, if possible. Whole herbs and spices last much longer than crushed or ground.
It's easy to grind or pulverize your spices with a mortar and pestle or a coffee grinder as needed. Whole spices last for years at a time in your pantry. Ground spices last for months.
If you do keep ground spices, be sure to check them for freshness at least once a year. Here's a good rule: If you can't smell the spice in the bottle or jar, replace it.
Keep your spices away from sources of heat. Of course that means the stove, but it also means your dishwasher or refrigerator, which can both produce more heat than you realize. The same goes for light.
Don't keep spices near a window or sunlight. Spice racks look nice but may put your spices right in harm's way.