I bought a timer switch for my bathroom fan.

The romex in the wall has the traditional black, white, and ground wires while the timer switch has one more, a red wire. I tried wiring it by connecting black to black and capping the red but the switch didn't work at all. Then I tried wiring the red to black (in romex) and capping the black - the led lights on the switch worked but the bath fan didn't turn on.