This is the path from a bare ceiling opening to a working bath fan. Follow the order. Each step sets up the next, and the last step tells you whether the earlier steps were done right.
Before you open the ceiling
Read the label on the fan you bought. Note the duct size it calls for, its airflow rating, and its mounting span. Confirm the fan will fit between the joists at the spot you chose, and that the spot has a clear duct path to an outside wall or the roof.
Turn the power off at the panel and label the breaker. Check the circuit with a tester before you touch a wire. Wiring at the switch and the box is work that many local rules reserve for a licensed electrician, so check those rules before you start. The electrical panel page on this site explains what to plan for when the panel is involved.
Electrical Panel: typical service life and when to plan
Set the housing
Mount the housing between the joists so the grille will sit flush with the finished ceiling. Keep the housing level and tight against the ceiling board. Do not rest it on the drywall alone. Leave enough access to reach the motor later.
Run the duct outside
Connect the duct to the outlet on the housing with the tape or clamp the fan calls for. Use the duct size on the label, not the size of the hole in the ceiling. Keep the run short and as straight as the framing allows, with as few bends as you can manage. Slope the run so condensation drains outward, away from the housing.
Terminate the duct outside the building, never into the attic, a soffit, or a crawl space. Install a backdraft damper at the outside end and check that its flap moves freely.
Wire the switch and the fan
Make the connections at the box with the power still off. Match the cable to the wiring diagram printed on the fan. Mount the switch where you can reach it from the door. If the fan has a timer or a humidity control, set it according to the instructions on the unit. Tuck the wires fully before you fit the cover plates.
Test before you close the ceiling
Restore power at the panel. Run the fan from the switch and listen for rattles or vibration that suggests the housing is not seated. Check the grille for air movement and feel the outside termination for flow. Confirm the damper opens while the fan runs and closes when it stops.
If anything is off, cut the power again before you touch the housing. Only when the test is clean should you close the ceiling. The grille trim goes on last.
Keep the record
Before the ceiling closes, photograph the fan label and write the install date next to the photo. Note the duct size and the controls you chose. That gives the next person a planning date without opening the ceiling again.