Whole spices last about 4 years; ground spices last about 6 months. Heat and light both cut that in half. Every spice rack above a stove is guaranteed to be selling stale product.
Whole vs ground
Ground spices have exposed surface area, so their essential oils oxidize and evaporate faster. Whole spices are protected by their outer layer. Buy whole where practical, grind before use.
The right container
Dark, cool cabinets. Tightly sealed opaque jars. Label with the buy date. When in doubt, crush a small amount and smell — muted or one-dimensional means replace. A fresh cardamom pod smells complex and floral; a three-year-old one smells vaguely of pine.
Exceptions
Paprika, chili powders, and turmeric fade especially fast — buy small quantities. Whole peppercorns, cumin seeds, and coriander seeds hold their oils longer and tolerate more neglect.