Well cover the easier scenario first. Except in rare cases it is a hot wire or a switched hot wire.

Motion Sensor Light Switch Install Cabin Diy
Light switch red wire. Attach the black wire coming from the light to the top right nut on the switch. Typically when a ceiling fan is installed the red wire is most commonly used for the light and the black is commonly for the fan motor. Attach the red wire coming from the light to the top left nut on the switch. Normally youll see a red wire in places you would expect a ceiling fan. Check the wire with a non contact voltage tester with the power and. Or it could be the red wire is the wire going to the fixture and the black wires are the live wires.
Twist the two white wires together and attach a wire nut. Red wire on the light fixture step 1 turn off the power to the light circuit then check the wires with a voltage tester to verify there is no voltage reading. If you change a light fixture and find a red wire in the electrical box chances are the black wire from the fixture needs to go to the redwire in the box. The red wire as a spare wire when a ceiling fan is not installed this spare red wire is insulated with electrical tape or capped off with a wire nut. When you see a red wire in a light switch box it can mean two things. The exact purpose of a red wire for a light fixture can vary.
More about wiring a light fixture. It could be there is or once was a three way switch in play.