Different medicines have different shelf lives. It all comes down to how stable they are - eg a tablet in foil will have a longer shelf life than a tablet in a bottle which will have a longer life than a capsule.

Some medications will only have a few days on them (liquid antibiotics are an example).

It is a while since I have used that part if the legislation but I am pretty sure that prescription medicines only have to have a useby longer than the use period - so a 40 pack of nebuliser nebules that you use say twice a day would only need to have 3 weeks remaining on it. Iykwim.