The heater has a transformer that steps down the line voltage supplied either 115v or 230v to 24 volts,a safe voltage to use for the thermostat's control voltage and a voltage which requires no license to install.
The most important thing to remember before you begin is that ,
Red or R is the "hot leg" of the 24 volts provided by the transformer and
Common or C is the "neutral leg" of the 24 volts provided by the transformer and
Common is the side of power which EVERY 24 volt circuit will terminate or return to in completing the circuit, thus the "Common " designation, note after each circuits device, be it AC or Heat or Fan,every 24 volt circuit returns to Common or it's circuit is not completed.
Every electric circuit ,regardless of voltage or polarity requires a device ,
without a device in a circuit, upon energizing that circuit it will be a direct short!
Red to Common, this will blow the fuse or worse the transformer if not protected by a fuse which some are not. If you have a device in the circuit you can energize a circuit, my point being do not let Red touch Common and as Common is grounded at the transformer, do not let Red touch any metal, as it is likely grounded too, so turn off power before doing anything.
Note the color of the wiring attached to your existing thermostat's terminals and make a diagram so you will not forget.
The new thermostat may have different terminals or more that you will not be using.
All thermostats have an R or Red terminal, it may be RC and an RH 2 separate terminals designating RC as red cool and RH as red heat.
There 2 terminals RC and RH are for 2 transformer systems which are obsolete old GE units so if you do have both RC and RH use a small jumper wire and connect the 2 terminals and wire the Red "hot leg" from the transformer to either RC or RH it will not matter if both are jumpered together, otherwise you will only have cooling or heating but not both available.
The Red hot leg of the 24 volts enters the thermostat on R and most modern thermostats are parasitically powered meaning they derive power from the heaters transformer, as a result the Common 24 volt neutral leg must be ran to the thermostat.
Note, the new NEST thermostats say they do not require Common to be wired, however 50% of the time the NEST will go dead in time and require a Common wire be used to power the thermostat satisfactorily.
Upon a call for heat the switch between the Red and White circuit closes making white electrically hot with the 24 volts which it sends out the white wire to the heater gas valve etc and return to common to complete the heat circuit.
Upon a call for AC the switch to Yellow closes and as you will notice the Fan switch on the thermostat has an AUTO and ON switch, in the AUTO position, upon a call for AC
the Yellow becomes hot with the 24 volts and as a result of the AUTO switch being closed, the indoor blower will automatically cycle as required.
The fan control for ON fan or AC is High speed, the fan control for heat is Low speed and controlled by a time or temperature delay at the initiation and termination of the heat cycle, this is to eliminate cold air from blowing until the heater warms up and upon termination it extracts the residual heat to not overheat the unit and be most efficient.
Green is the Fan circuit, it is the High speed fan and only used for heating with electric heaters as resistive heat strips or heat pumps and will be controlled in both heat and cool modes by the thermostat, this is designed in to the thermostat or part of the thermostats set up and programming if a universal type thermostat.
Common as explained is there to power the thermostat it being the other side of 24 volt power opposite from the red 24 volt hot leg.
Heat pumps will have an O and a B terminal, this gets the Orange wire on O if the reversing valve is energized in cool mode, if you get heat in the cool mode switch the Orange wire from O and put it on B, B is energized in the Heat mode.
This was not written for just heat pumps or any brand I had to pick a specific brand however this applies to all brands and types gas furnaces , heat pumps and electric heat.