A dirty mattress is gross, and if it smells bad then chances are no one wants to sleep on it. Fortunately, this doesn't spell total disaster if you know how to tackle the odour the right way. With the right supplies, you can actually clean a smelly mattress in just a few hours.
There are several cleaning solutions on the market specifically for mattresses. If you can't find a mattress cleaner at either your local grocery store or online, use upholstery shampoo. There are even some mattress kits out there that come with a black light so you can find hard-to-see stains like urine.
Apply a thin layer of powdered carpet cleaner to the mattress. Use a damp sponge or rag to soak the powder into the mattress. This can be time-consuming, so it helps if you focus on one stain or source of the bad odour to work on instead of soaking the whole mattress.
Vacuum the mattress thoroughly and then take it outside in the morning. Let it sit in the sun all day long, and bring it in before the sun goes down. Let the mattress sit in the sun for several days if necessary. This will kill several odours including those from cigarette smoke, and mildew or mould.