When gallstones become lodged in the duct (tube) leading to the stomach, they block the outflow of bile, causing the gallbladder to spasm. This usually causes sharp pain under the rib cage in the upper right side or centre of the abdomen, similar to being cut with a knife.