Most manufacturers now recommend that helmets be replaced after five years, but some of that is just marketing. Deterioration depends on usage, care, and abuse. If you ride thousands of miles every year, five years may be right. You must replace the helmet after any crash where your head hit. The foam part of a helmet is made for one time use, and after crushing once it is no longer as protective as it was, even if it still looks intact.
Plastic shells hide the foam damage.
If you can see or measure any foam crush at all, replace the helmet. If in doubt, contact the manufacturer for an inspection. Fifteen states require helmets for some riders, usually under age 16. So do over 50 cities and counties. We have the current list up on our Web server.