Frozen food: slowly. Canned food (if still hermetically sealed): never. The "going bad" concerns quality/taste, not safety.
I've had a few occasions where someone cleared out cabinets in their kitchen, and gave contents away. General findings:
Dry stuff (pasta, cookies, rice, beans, spices, etc): fine for years (if not a decade+) past its best-before date.
Canned food: if hermetic seal is intact, it's edible. Personal record: ~25y old fruit cocktail. Physical structure was poor and taste was bland, but it was edible.
For fresh foods like meat, dairy, vegetables etc: look, feel & sniff. It's almost always obvious when it's gone bad.
> Canned food: if hermetic seal is intact, it's edible.
Definitely not a universal truth. Canned food can develop botulism, you do not want to mess with it. Any cans that are bulged or show signs of swelling should be discarded - don't even risk opening them.
There are guys on YouTube who explore old army rations (which were basically all canned food prior to the 1980s), and when they decide to open a bulged can "for science" they will often literally break out a gas mask. That said, it's also not terribly uncommon for them to find rations dating back to WW2 and older that are still partially edible.
Dried spices vary by volatility and oxidizability.
I tried some 10 year old saffron kept in a corked vial, and it really didn't do much. I basically had to use the whole thing to get any yellow out of it, probably $20 worth.
I've had a few occasions where someone cleared out cabinets in their kitchen, and gave contents away. General findings:
Dry stuff (pasta, cookies, rice, beans, spices, etc): fine for years (if not a decade+) past its best-before date.
Canned food: if hermetic seal is intact, it's edible. Personal record: ~25y old fruit cocktail. Physical structure was poor and taste was bland, but it was edible.
For fresh foods like meat, dairy, vegetables etc: look, feel & sniff. It's almost always obvious when it's gone bad.