Some advice from someone who's had lots of broken ribs (6 or 7 over the years). Before you cough, sneeze (especially), turn over in bed or otherwise do anything that will stress the affected area, tense your whole ribcage. Contract your abdomen and tighten your whole shoulder area – this means the damaged rib is supported by the others around it and the muscles spread the strain over a larger area.
A surprise sneeze is enough to snap a rib that is otherwise only fractured.
I would also advise using the minimum of pain-killers, pain is your friend and will help you avoid doing too much and lengthening your recovery.