Even freezing air contains heat. A heat pump moves a fluid through its system that is cold enough to take in some outdoor heat.
The fluid becomes a gas. A compressor—a part that squeezes the gas—raises its pressure and temperature. It can then release heat indoors. Electricity keeps the process going.
As outdoor air gets colder, this generally takes more work. Melting frost on the equipment can add work too.