What ice and heat are for:
Ice is for injuries, and heat is for muscles. Roughly.
Ice is for injuries — calming down damaged superficial tissues that are inflamed, red, hot and swollen. The inflammatory process is a healthy, normal, natural process that also happens to be incredibly painful and more biologically stubborn than it needs to be. Icing is mostly just a mild, drugless way of dulling the pain of inflammation. Examples: a freshly pulled muscle or a new case of IT band syndrome (which is more likely to respond than the other kind of runner’s knee, patellofemoral pain, because ITBS is superficial and PFPS is often a problem with deeper tissues).
Heat is for muscles, chronic pain, and stress — taking the edge off the pain of whole muscle spasms and trigger points, or conditions that are often dominated by them, like back pain and neck pain), for soothing the nervous system and the mind (stress and fear are major factors in many chronic pain problems, of course).
What ice and heat are not for:
Heat can make inflammation worse, and ice can make muscle tension and spasms worse, so they have the potential to do some mild harm when mixed up.
Both ice and heat are pointless or worse when unwanted: icing when you’re already shivering, or heating when you’re already sweating. The brain may interpret an excess of either one as a threat — and when brains think there’s a threat, they may also amp up the pain.
But heat and inflammation are a particularly bad combination. If you add heat to an fresh injury, watch out: it’s going to get worse! If you heat a freshly injured knee, it can swell up like a balloon, and three times more painful. (That is a rare example of a particularly severe negative reaction to heat. Most cases are not going to be that bad!)
The lesser known threat is from icing at the wrong time, or when it’s unwanted.
If you ice painful muscles, be careful: it might get worse! Ice can aggravate sensations of muscle pain and stiffness, which are often present in low back and neck pain. Trigger points (painfully sensitive spots) can be surprisingly intense and easily mistaken for "iceable" injury and inflammation. But if you ice trigger points, they may burn and ache even more acutely. This mistake is made particularly often with low back pain and neck pain — the very condition people often try to treat with ice.
What about injured muscle?
If you’re supposed to ice injuries, but not muscle pain, what do you with injured muscles (a muscle tear or muscle strain)? That can be a tough call, but ice usually wins — but only for the first few days at most, and only if it really is a true muscle injury. A true muscle injury usually involves obvious trauma during intense effort, causing severe pain suddenly. If the muscle is truly torn, then use ice to take the edge off the inflammation at first. Once the worst is over, switch to heat.
Which is better?
Ice packs and heating pads are not especially powerful medicine: some experiments have shown that both have only mild benefits, and those benefits are roughly equal in treating back pain.
The bottom line
The bottom line is: use whatever feels best to you! Your own preference is the tie-breaker and probably the most important consideration. For instance, heat cannot help if you already feel unpleasantly flushed and don’t want to be heated. And ice is unlikely to be effective if you have a chill and hate the idea of being iced!
If you start to use one and you don’t like the feel of it... just switch to the other.