Many pains are due to small muscle strains; one guideline for relatively mild pain is to sit with it for a week or two and see if it resolves itself - most muscle strains do resolve themselves in that time. There are muscles under the ribs that help the ribcage flex up and down when you breathe and straining one of them can be quite painful. It's possible this could be the cause but you need to see a doctor to determine what's going on.
In any case, if the pain increases substantially beyond a dull ache or if you have other symptoms or if its continuing be sure to contact your doctor. Good luck.
Nerves in the back are pinched.