The cable has a black wire which connects directly to the circuit and a red wire which connects to the switch. When you see a red wire in a light switch box it can mean two things.
55b9 Electrical Wiring Colors Red Black White Wiring Library
Red white and black wires. White wires augmented with red or black tape or markings are used as hot. As hot wires can be connected to each other a black wire can be connected to a red wire. The ground wire also connects to the switch but the white wire gets spliced to the circuit neutral wire and bypasses the switch. Well cover the easier scenario first. 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. The white wire of the ceiling fan is the main neutral for both the light fixture and the fan motor.
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. The black wire goes to the bundle of black wires. Regardless of output setting power will be applied to this wire. In almost every motor design the white wire will be the neutral. 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. 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.
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. Then the red wire in your box goes to the non white wire on your ceiling fan which is often blue. The white wire is the neutral and all other colors are hot. It could be there is or once was a three way switch in play. Typically this is indicated with a band of black or red electrical tape but other colors may be used wrapped around the wires insulation. Or it could be the red wire is the wire going to the fixture and the black wires are the live wires.
They may use other colors for. 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. This wire is always on so make sure that there is no current when dealing directly with this one to avoid any injury. Electricians often use black red or blue wires to deliver electricity to a circuit from the main panel. The white wires on the fan go to the bundle of white wires. Red wires are also hot 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. Being the main hot wire the primary function of the black wire is to provide current to the fans motor.