Pain under your ribs when breathing is something that can happen sporadically due to a number of different reasons. Some of the more innocent underlying etiologies include things like muscle cramping during times of strenuous activity while others can be more menacing in nature. Here, we will cover some of the possible causes to help you get to the bottom of what could be causing your rib pain.
The first sickness to consider is a textbook description of what doctors think of first when they hear a patient presenting with tenderness in their rib cage while breathing. Costochondritis is a condition where there is inflammation of the costochondral junction in the rib cage that can be aggravated when a patient breaths . Studies show that low levels of Vitamin D could predispose patients to develop this condition . There is no real understanding of what causes this inflammation in the first place. Some theories postulate that the inflammation is secondary to potentially bouts of viral infections or repetitive minor trauma to the chest wall . This condition will resolve as quickly as it appeared usually but anti-inflammation medication is usually used to accelerate healing .
Another condition linked to pain under your ribs from breathing could be from more systemic illnesses like pneumonia infections. When patients have fluid collect in their lungs during an infection, more effort and muscle stress occurs. Pain when breathing can indicate muscle fatigue and patients should begin antibiotics immediately if they are not already taking them to avoid potential long-term complications of pneumonia infections. 
Similar to the first two conditions, muscle cramping can manifest as pain under your ribs. When electrolyte levels are unbalanced during times of exercise or extreme exertion, muscles can easily begin to cramp. This is a common injury in active patients who fail to warm-up properly and disregard pre-workout stretching. Muscle cramping will often occur in the first 10 minutes of the exercise so it is important to ensure you are in the proper physiological state of mind before any type of exercise routine. 
Something more menacing that could present with pain under your ribs when breathing would be having a pulmonary embolism. Pulmonary embolisms occur after patients have some type of clot from in their veins due to prolonged immobility. Elderly patients and those who are bed-ridden due to operations are very susceptible to this type of coagulopathy and it is something physicians are quite concerned with after any procedure. The clot will usually start in the legs and when it becomes dislodged, it will travel through the bloodstream to your lungs and block blood flow. Patients will present with sharp chest pain and severe dyspnea and urgent medical attention is necessary to try to save the life of the patient. Making sure patients move joints as much as possible and taking blood-thinning medications are two techniques that we use often to try to make the risk for clotting less likely.
An equally sinister cause of pain under your ribs when breathing could be from some type of ischemic event like a myocardial infarction, better known as a heart attack. When there is insufficient blood traveling through your body, even simple actions like breathing could lead to severe chest pain. Patients with a history of kidney problems and diabetes are most prone to heart attacks but obesity, poor cholesterol levels, and smoking are also potential aggravating factors. Call the ambulance immediately if you start to feel dull chest pain that travels to your arms or jaw so urgent medical attention can begin. 
Another systemic disease that could have presentations of chest pain would be systemic lupus erythematosus (SLE). This is a very common autoimmune disease most likely seen in female patients. Not only may patients develop rashes when exposed to sunlight, they also have a high risk for kidney and heart problems because of the autoimmune attack. Should you have a number of bizarre symptoms that physicians are struggling to tell you what is causing them, ask about the possibility of SLE affecting you. 
Another potential cause of pain under your ribs when breathing can come from a more obvious source, any type of mechanical injury that you may have suffered. Blunt force trauma from car accidents or contact sports can be two ways you can easily break ribs. Patients should go to the clinic immediately to have a chest X-ray looking for signs of possible fractures after these types of injuries. 
Cancer is the last possibility worth mentioning when someone presents with pain under your ribs when breathing. Patients who have lung cancer are most likely to present with this type of pain. Weight loss and difficulty breathing could also suggest this type of pathology. Patients need to get a CT-scan of their chests immediately if they have a long pack-year history of smoking to make sure this pain is not linked to tumor growth in their lungs.