How to connect a DIY thermostat to the HVAC System
Since you haven't supplied much detail, I'll have to use nonspecific examples based on typical installation methods.
Furnace and Condensing unit
If you have a setup where you have a furnace, and an outdoor condensing unit. The wiring will be similar to this (Note: This is a basic overview, not actual wiring).

Basically, the R wire provides power to the thermostat. W, Y and G are energized depending on the state of the thermostat. For example. If the thermostat is set to the COOL mode, and the temperature in the room is above the set point. The Y and G terminals of the thermostat will be energized. This tells the furnace to turn on the blower at high speed, and  the condensing unit to turn on. Alternatively, if the thermostat is set to the HEAT mode, and the temperature in the room is below the set point. The W terminal will be energized, which tells the furnace to turn on.
Heat Pump
If you have a heat pump, the wiring will be similar to this.

Here the R wire again provides power to the thermostat. This type of setup uses either an O, B, or O/B terminals to change the state of the reversing valve in the heat pump. In this type of setup, the thermostat works similar to the example above, though it also has to manage an extra terminal.
Some thermostats offer both an O and a B terminal.

When the thermostat is in COOL mode and calls for cool, the O terminal will be energized. If you have a system where the reversing valve is normally in HEAT mode, you'll use the O terminal to move the reversing valve to COOL mode.  When the thermostat is in HEAT mode and calls for heat, the B terminal will be energized. If you have a system where the reversing valve is normally in COOL mode, you'll use the B terminal to move the reversing valve to HEAT mode.
Some thermostats offer and O/B terminal, and will have a jumper to select which function it provides.

In this case, you'll set the jumper based on the type of system you have. Then when the thermostat calls for heat or cool, the O/B terminal will be energized appropriately.
For more information on the C terminal, please see this answer.