How can you tell if its costochondritis or a cracked/broken rib?

Imaging. Typically, a rib series radiography would help. Costochondritis is invisible on x-ray.
History and physical. A broken rib typically follows an injury, such as car accident or direct impact - x-rays or, if necessary ct, and make the diagnosis. In the absence of injury or imaging findings of fracture, costochondritis is a possibility, and is localized to a particular area of the ribcage, so physical exam would help make the diagnosis.