Heavy machine gun refers to two distinct classes of weapon from two distinct points in history.
In the era around World War 1, the term was applied on the basis of the sheer weight of the weapon itself: a gun large enough that it could not easily be relocated was a heavy machine gun. This use survived into World War 2 with the Japanese rifle-caliber "heavy" machine guns which were derived from the WW1-era Hotchkiss.
The modern use refers to an automatic support weapon firing a projectile with a caliber of 0.5 inches (12.7mm) or larger, but less than 20mm (any larger and it is an autocannon). This usage stems from the M2 Browning machine gun, an enlarged version of the M1919 Browning machine gun developed in response to the appearance of the metal-bodied Junkers J.I ground-attack aircraft in 1917, which proved immune to conventional rifle ammunition. The term switched to its modern meaning during the Cold War, as medium machine guns in general had fallen out of favour, nevermind examples that could be regarded as "heavy."
WW1-era heavy machine guns were used to defend specific points, as their lack of mobility meant they could not easily be moved to support infantry actions. They proved a key component of trench warfare.
Modern heavy machine guns are most commonly used to provide heavy supporting fire, particularly against troops in cover, light vehicles and helicopters. While formerly used in the anti-aircraft role, they became obsolete in this regard during World War 2 as aircraft flew faster and higher, being discarded first as anti-aircraft and then as aircraft weapons.