Both ASHRAE 62 and ASHRAE 62.2-2007 require that a bathroom fan be capable of venting 50 CFM on demand, which means whenever someone turns on the fan. However, if the fan runs continuously--for example, as soon as the light switch turns on, it must vent 20 CFM.
You must ensure the moist air from the bathroom gets vented outside the house. Do not terminate the pipe for the fan in the attic, as this can create a conducive environment for mold and rot. Always vent the bathroom fan through the roof and extend the pipe above the roof. By installing a cap meant for ventilation fans, you can prevent cold air going back down the pipe, as well as debris, insects and other unwanted creatures.
The final step in properly ventilating your bathroom is insulating the pipe that exhausts the moist air. This prevents the moist air from going back down the pipe when exposed to the varying temperatures in the walls or in the attic of your house. Any kind of flexible insulation works well, such as flexible foil insulation, batt insulation or even spray foam insulation.