Understanding driving a relay with a transistor

For an embedded application, I'd like to drive a relay using a transistor. At the moment I'm experimenting with a BC547, but only because I've still got some of them lying around.

The transistor I am using is rated at a max of 100mA continuous for the collector (or collector-emitter) current (if I exceed that it gets really hot and would eventually get destroyed, I guess). A typical relay that I'd probably use would have a coil resistance of e.g. 225 Ω and a nominal switching current of 53 mA at 12 V (I'd opt to use a 12 V relay, because I already have 3.3 V and 12 V in my circuit).

I'd guess that the nominal switching current simply equates to the voltage devided by the resistance, am I right? Hence I assume that it would be safe driving the relay with the transistor, because the current should not exceed the 53 mV, which is well below the maximum current the transistor can bear. Am I correct?

(I am aware that the description only holds for the static state when the relay is shut. I do know that there will be spikes induced by the coil when the relay switches, that have to be buffered using a diode.)

For reasons that have little to do with the static calculations in the other answers, I would use a beefier transistor such as the 600mA 2N4401 or a MOSFET. Switching an inductive load is harder on the transistor than switching a resistive load, even with the diode. At some point the full relay coil current is flowing through the transistor for a short period of time with more than 12V across it. SOA is unspecified on many of the small transistors.

Give a 2N4401 a few mA of base current and it will be happy switching your inductive 53mA load, and don't forget the diode across the coil. If you need to operate in extreme cold conditions, 5 or 6mA would be better.

You should also calculate the transistor's power dissipation to make sure it doesn't overheat. Note that when the relay is on, the voltage across the transistor is only about 0.2V (this is a typical number for silicon transistors), not the full 12V - the remainder is across the relay. The power dissipation should be about 0.2V x 0.053A = 0.0106W. I would expect that to be just fine without a heatsink, but if you want, you can calculate the temperature the transistor will reach, based on the thermal resistance specified in the datasheet.

(Note that the relay only gets 11.8V across it, not 12V, so the current is slightly lower than 53mA, but it's such a small difference, 53mA is good enough for this calculation)

This assumes the dissipation from base current (which controls the transistor) is much less than the dissipation from the collector current (which goes through the relay). If your base resistor is way too low, it could dissipate extra power in the base. If your base resistor is way too high, the transistor might not turn fully on, and the voltage across it might be more than 0.2V, which also increases power dissipation in the transistor.

A PN2222A has a4 Ohm Rce while the 2N290x series is about 7 Ohms but in order to achieve this with Vce=Vce(sat) they are rated with Ic/Ib=10

So try to achieve 10% to 5% of relay coil current if possible. CMOS logic in the 74HC' family is about 50 Ohms so keep that in mind in series with your base R.

if you use only 1% then a higher Vce and power dissipation may occur.

A 1N4148 diode is sufficient for reverse BEMF clamping to Vcc.