Just to be difficult, the answer is both!
This piece of advice is as helpful as a chocolate teapot. Therefore, I will try to explain when to use ice and when to use heat in the following paragraphs.
The first thing to think about is that cold reduces inflammation which reduces swelling, redness and soreness. Heat increases new blood flow into the area which brings with it nutrients and inflammatory chemicals. This promotes healing and relaxation. So, now that we know what ice and heat do, we can start to understand when to use them.
If you have a sharp, catching pain that almost takes your breath away, you are probably experiencing inflammatory pain. Most commonly this comes from joints and occasionally tendons and ligaments. You would almost certainly need to use ice to reduce the inflammation and thereby reduce the pain. I recommend using an ice pack for around 15 minutes at a time. 20 minutes is okay if you are thick set are using it on your lower back. 5 minutes is enough if you are using ice on your hand or foot as their isn't much padding for the ice to permeate. Remember to wrap the ice pack in a tea towel or pillow case as freezer burn is not nice. When you are finished, pop the ice pack into the freezer for 30-40 minutes and then repeat. If it's easier, just use the ice pack once an hour for 15 minutes until the sharp pain has gone. I do understand that real life means that may not be possible. Just do what you can, the more the merrier.
If you have an aching, dull pain that seems to be ever present and annoying, you are probably experiencing muscle tightness or over-activity. You would be better served using heat to relax the muscles and flood them with nutrients so that they can heal. I recommend using heat in the same way as ice, except that with heat, it's harder to overdo it. If you left a heat pack on for 30-40 minutes nothing bad would happen. If you left ice on for too long, you can damage the tissues. Use heat in the same way as the ice, once an hour until things have improved. Incidentally, if you have a long-term (chronic) condition such as wear and tear in your joints (osteoarthritis), heat can be used to ease the pain and stiffness associated with this.
So, in summary, the sharper and newer (acute) the pain, the more likely it is that you should use an ice pack. The duller, more achey and longer lasting (chronic) the pain, the more likely it is that a heat pack would be best.
Acute and sharp = ice.
Chronic and achey = heat.
We have packs that can be frozen or microwaved available in both clinics for £5. They last around five years and can be constantly re-used.
For a bit of fun, the first person who correctly tells me the most common question I am asked wins a brand new ice/heat pack.
Good luck and happy icing. Or heating obviously.