What causes pain under ribs on right side?

Many reasons. It depends on what brings the pain on, what it feels like, where exactly it is located, how long it lasts, what makes it better, and what makes it worse. Only a dr. Can help you figure this out. Possibilities include an ulcer, irritation of the stomach or duodenum (small intestine), gallstones, congestive heart failure, muscle spasms, pinching of nerves that exit the back, or spasms of intestine.