A bathroom exhaust fan swap runs in a fixed order. Each stage sets up the next, and the airflow test at the end tells you whether the earlier stages were done right. Work through the stages below in order.
Before the tools come out
Turn off the circuit at the panel. Confirm the fan leads are dead with a voltage tester before you touch them. Check local permit rules if the fan needs new wiring or a new circuit.
Open the ceiling
Remove the grille and the cover. Measure the existing housing and the ceiling opening. Note the joist spacing and the clearance above the ceiling. Look for insulation that would press on the housing.
Check the duct
Trace the duct to the outside. It should end at an exterior vent with a damper that opens and closes freely. It should not end in the attic. Check the duct size against the housing outlet. Look for sagging flex duct, crushed sections, and long runs with many turns. Each of these cuts airflow.
Pick the unit
Match the new fan to the room size and the duct. Check the airflow rating and the noise rating in sones. A higher airflow rating does not help if the duct cannot carry it. Check that the housing fits between the joists.
Set the housing
Install the housing as the maker's instructions describe. Keep insulation clear of it if the maker requires that. Seal the housing to the ceiling as the instructions say.
Connect the duct
Attach the duct to the housing with foil tape. Plain duct tape is not the tape for this joint. Keep the run as short and straight as the layout allows.
Wire it
Connect the leads to the house wiring as the instructions show. The ground goes on before the hot leads. If the box, the cable, or the switch arrangement is not clear to you, stop and call a licensed electrician. Do not guess at the connection.
Test the pull
Restore power. Run the fan. Check that the exterior damper opens while the fan runs. Hold a light tissue or a strip of paper near the grille to feel the pull. Listen for rattles and judge the noise. If the fan has a humidity sensor, test its setting.
Hand off the record
Write the install date, the model, the airflow rating, and the duct route on the paper you keep. Note when you last cleaned the grille and the cover. Plan the next check at the same time you plan the other fans and vents in the house.