Ribs may hurt for many reasons, such as trauma (bumped into something, somebody poked a finger into the ribs), coughing (bad cold & cough
(breathing heavily for a while), weight training
or sit-ups (over exertion while exercising), irritation in the rib's bones/muscles/cartilage
/linings, a tumor (rare), etc.
.. If symptoms don't go away quickly, one must visit a doctor.