Okay I know that just about everyone out there has herbs and spices in their cupboard that they have no idea how long they've been there. And every time you open that cupboard or drawer you ask yourself "How long have I had this, and is it still good?"
Here's the low down for you. Whole spices are good for up to 3 or 4 years. These are things like nutmeg, peppercorns, cinnamon sticks, cloves, cardamom pods, star anise, etc. Ground spices don't really go bad, and neither do dried herbs. However, they both lose potency after a while. You have about 2 - 3 years for ground spices and about 1 - 3 years for dried herbs. This doesn't mean they're bad, they just might not have as much flavor as something that hasn't sat around in your cupboard for as long. There are a couple ways you can test them. First take a look at the colors. Chances are if they are still vibrant they're probably still pretty good. If they've lost color, they've probably lost flavor too. You can also test them by taking out a pinch and rubbing them between your thumb and forefinger. If they are still nice and fragrant, they're still good. When the aroma is weak or flat it's best to toss them and start fresh.
As for your bottles of extracts, they tend to fade after about 4 years. All except PURE vanilla which lasts indefinitely.
Please, please please do not store your herbs and spices on the back of the stove, close to the sink or the dishwasher, in the cupboard above the stove, or near a window. Keep them away from heat, moisture and direct sunlight. This affects their quality, viability, color and flavor. And can cause ground items to clump or become hard blocks due to moisture or steam.
Store your herbs and spices tightly sealed in a dark cupboard, the pantry or in drawers that are dark and cool to help maintain their quality. They'll thank you for it and stay better for you longer!!!
One more thing, don't sprinkle herbs or spices directly from the bottle over steaming/simmering pots, this can cause moisture to enter the container and degrade the product or cause caking and or clumping. Remove what you need from the bottle or container into another measure, cup or bowl then add to your food. This will help you keep your herbs and spices in the best shape. And when using measuring spoons, be sure they're completely dry before dipping into your tins or jars too. You don't want to introduce moisture that way either!
I hope this helps! Enjoy and happy cooking!