Applying ice or heat can provide relief from injuries, aches, and pains, but they shouldn’t be used interchangeably. Generally speaking, ice works well after a sudden injury while heat helps to soothe ongoing muscle aches and pains.
Ice works for injuries because it narrows your blood vessels, which helps prevent blood from accumulating at the site of injury, which will add to inflammation and swelling while delaying healing. This is also why elevation is helpful, since it limits blood flow to the area to minimize swelling.