Different type of ammo have differing reliable shelf lives. Currently manufactured commercial centerfire ammo can be stored for up to at least 20 years. Military spec ammo is expected to be reliable after storage of 20 to 25 years. As for any modern ammo, you probably if you store it well, you likely can still have it shooting reliably after 50 years but that is my guess at best. I have some handgun ammo that is at least 30 years old and it still fires reliably. The thing is though, modern priming material does break down as opposed to older corrosive priming material which would last much longer and that could be a problem after very long term storage.
As to rimfire ammunition, I have had some in storage that is from at least the late 1970's (maybe even the mid or early 70's) and it fires as good as it would have when new. Something to be careful of with older .22 rimfire ammo is that the lead bullets they used then were often covered with an oily substance. Once the oil is gone, so is the lubrication it provided. Another thing about lead bullets is that lead does eventually break down. If an old lead bullet looks whitish, those bullets may not be safe to fire and may actually be stuck in the shell casing due to this degradation/corrosion.
Shotgun shells of current manufacture can last a good long time too. I recently shot up my last batch from about 20 years ago. Not one misfire or mishap. Note though that these were plastic and brass shotshells and not older paper and brass shotshells. I would imagine that paper shotgun shells would degrade much faster than those made of plastic.
As far as storage goes, keep it dry and keep it relatively cool (temps in the low to mid seventies). That is what I do, and I have no problems with ammo that I have had in long term storage. Yet, I do not like to go overboard in taking chances with stored ammunition, so every now and again I rotate my stock. I buy some freshly manufactured ammo and shoot up the old stuff. This serves a few purposes: I am sure to have fresher ammo on hand for a longer time, I get in needed training and practice while shooting up the older stuff, and I help keep ammo companies and ammo dealers in business. I recommend dating boxes of ammunition with the acquisition date and manufacture date (if known). Then rotating it on a fairly frequent basis with newer ammo. This way you will not have to worry about whether or not older stored ammo has retained its integrity.
All the best,
Glenn B