The ground wire also connects to the switch but the white wire gets spliced to the circuit neutral wire and bypasses the switch. The white red and black wires in an electric ac motor supply power to the motor itself and determine which of the speed coils turn on when electricity is supplied.

2 Black Wires 2 White Wires And 1 Red Wire Doityourself
Red white and black wires. The white wires on the fan go to the bundle of white wires. When a white wire is augmented with a red or black color marking this often indicates that it is being used as a hot wire rather than a neutral wire. They may use other colors for. Regardless of output setting power will be applied to this wire. It could be there is or once was a three way switch in play. When you see a red wire in a light switch box it can mean two things.
Or it could be the red wire is the wire going to the fixture and the black wires are the live wires. One of the hot wires attaches to a brass terminal on one side of the outlet and the other attaches to a brass terminal on the other side. White wires are always neutral in 110 volt circuits but can be used as the second hot wire or switch leg in 240 volt applications and three way switches respectively. Red wires are also hot wires. The cable has a black wire which connects directly to the circuit and a red wire which connects to the switch. Typically this is indicated with a band of black or red electrical tape but other colors may be used wrapped around the wires insulation.
Well cover the easier scenario first. The black wire goes to the bundle of black wires. However a black wire can never be used as a neutral or ground wire or for any purpose other than to carry a live electrical load. If you only have black wires in your box connect both the non white wires from the fan to the black wires in the box. Being the main hot wire the primary function of the black wire is to provide current to the fans motor. The white wire of the ceiling fan is the main neutral for both the light fixture and the fan motor.
Electricians often use black red or blue wires to deliver electricity to a circuit from the main panel. This wire is always on so make sure that there is no current when dealing directly with this one to avoid any injury. The white wire is the neutral and all other colors are hot. As hot wires can be connected to each other a black wire can be connected to a red wire. In almost every motor design the white wire will be the neutral. White wires augmented with red or black tape or markings are used as hot.
Then the red wire in your box goes to the non white wire on your ceiling fan which is often blue. When measured with respect to the white neutral wire the red wire carries the same 120 volt current that the black one carries making the voltage across these two hot wires 240 volts.