A bathroom exhaust fan removes the moisture that would otherwise feed mould, peel paint, and rot trim. It's a code requirement in bathrooms without an operable window, and good practice everywhere.
Vent it outside
The fan must vent to the outdoors — through the roof or an exterior wall — never into the attic or a wall cavity, where the dumped moisture causes hidden mould and rot. This is the single most important rule, and a common mistake in older or DIY installs.
Size it right
Fans are rated in CFM (airflow). A rough guide is at least 1 CFM per square foot of bathroom for typical sizes, more for large bathrooms or those with a separate shower or tub room. An undersized fan can't clear the moisture.
Use it long enough
Run the fan during the shower and for 15 to 20 minutes after to fully clear the humidity. A timer switch or humidity-sensing fan handles this automatically and is a cheap, worthwhile upgrade.