A heat pump can provide both cooling and heating for indoor spaces by reversing the direction of the refrigerant flow using a reversing valve. In cooling mode, it works similar to a regular air conditioner to pump heat from indoors to outdoors. In heating mode, it operates opposite by pumping heat from outdoors to indoors. This allows a heat pump to serve the purpose of both air conditioning and heating using the same basic system. Proper sizing of air conditioners considers factors like building dimensions, insulation, heat loads, and location to determine the optimal tonnage required.