The fan is turned on or off as needed based on the temperature of the engine. When the engine is hot, the fan is on to help cool it down. When the engine is cool, the fan is off to save energy.
Some cars also have a fan that is used to circulate air in the passenger compartment. This fan is called the blower fan. The blower fan can be turned on or off independently of the engine fan.