Analog

Transistor As a Switch

By CourseTron Team ·  7 min read ·  Updated Oct 2026 💬 𝕏 in f
Table of Contents

    ? Print / Save as PDF

    In short: To use an NPN BJT as a switch, drive the base with enough current (about Ic/10) through a resistor Rb = (Vdrive − 0.7 V)/Ib so the transistor saturates with Vce(sat) near 0.2 V, and add a flyback diode when the load is inductive.

    Every microcontroller pin eventually meets a load it cannot drive directly: a 30 mA relay coil, a buzzer, a string of LEDs. The humble bipolar junction transistor (BJT) is still the cheapest, most forgiving answer, and "size the base resistor for this relay" is a favourite interview question precisely because it exposes whether you understand saturation or just memorised a formula. This article builds the design from first principles and finishes with a worked example you can reproduce on a bench or in SPICE.

    Two states, not three

    An amplifier lives in the forward-active region, where Ic = β·Ib and Vce floats somewhere in the middle. A switch deliberately avoids that region and lives at the two ends of the load line:

    • Cutoff: Vbe is below roughly 0.5 V, so the base-emitter junction does not conduct. Ic is only leakage (nanoamps), Vce equals the supply, and the load sees almost no current. The transistor is an open switch.
    • Saturation: both junctions are forward biased. Vce collapses to Vce(sat), typically 0.1 to 0.3 V for a small-signal part like the 2N3904 at 10 mA. Collector current is set by the supply and the load, not by the transistor. The transistor is a closed switch with a small voltage drop.

    Key fact: in saturation the gain relationship Ic = β·Ib no longer holds. The load decides Ic; the base only has to supply at least Ic/β to keep the transistor pinned at the low-voltage end.

    NPN low-side switch driving a 12 V relay +12 V Relay coil RL = 400 Ω Flyback diode 1N4148 GND Vin 0 / 5 V Rb = 1.5 kΩ Ib = 2.9 mA Ic = 30 mA Vce(sat) ≈ 0.2 V forced β = 10 CourseTron · coursetron.com
    Low-side NPN switch: the base resistor sets Ib, the load sets Ic, and the diode gives the coil current somewhere to go when the transistor turns off.

    Sizing the base resistor, step by step

    The method has four moves, and the order matters.

    • 1. Find the load current. Ic = (Vcc − Vce(sat)) / RL. For a 12 V, 400 Ω relay coil: (12 − 0.2)/400 ≈ 29.5 mA, call it 30 mA.
    • 2. Choose a forced beta. Datasheet hFE (say 100 to 300 for a 2N3904) is a typical active-region figure and varies with temperature and lot. Design with a forced beta of about 10 so a weak or hot part still saturates: Ib = 30 mA / 10 = 3 mA.
    • 3. Compute Rb. With a 5 V drive and Vbe(sat) near 0.75 V: Rb = (5 − 0.75)/3 mA ≈ 1.42 kΩ. Pick the nearest standard value that gives more base current, so 1.2 kΩ or 1.5 kΩ with margin. We use 1.5 kΩ, giving Ib ≈ 2.8 mA and an actual forced beta near 10.6.
    • 4. Check the source. A 3.3 V GPIO with 8 mA drive can supply 2.8 mA only if its output voltage still holds near 3.3 V. Recompute Rb with 3.3 V: (3.3 − 0.75)/3 mA ≈ 850 Ω, so choose 820 Ω.

    Key fact: overdriving costs very little, since extra base current just wastes milliwatts, while underdriving leaves the transistor in the active region, where it can dissipate Vce × Ic and run hot.

    Load line: the switch lives at its two ends Vce (V) Ic (mA) ON point: Ic = 30 mA, Vce ≈ 0.2 V (saturation, strip at left) OFF point: Ic ≈ 0, Vce = 12 V cutoff strip (Ib = 0) 400 Ω load line Active region = everything between: avoid dwelling there. CourseTron · coursetron.com
    The 400 Ω load line crosses the BJT characteristics. Switching means jumping between the cutoff end and the saturation end, spending as little time as possible in between.

    Watch it switch

    The animation below follows one full cycle. When Vin rises, base current flows, the collector node is dragged from 12 V down to about 0.2 V and the relay indicator lights. When Vin falls, the transistor cuts off and the collector snaps back up.

    Input vs collector voltage (inverting switch) Vin Vc 5 V 0 V 12 V 0.2 V Relay cutoff saturation cutoff CourseTron · coursetron.com
    The orange scan line sweeps one period; the relay indicator turns amber only while the collector sits at Vce(sat).

    Real-world limits: storage time and Baker clamps

    A saturated BJT stores excess charge in its base. On turn-off that charge must be removed before Vce can rise, producing a storage delay of tens to hundreds of nanoseconds for small parts and microseconds for power devices. The deeper you overdrive, the longer the delay. Three common fixes:

    • Moderate overdrive (forced beta 10, not 100).
    • A speed-up capacitor (100 pF to 1 nF) across Rb to pull charge out on the falling edge.
    • A Baker (Schottky) clamp from base to collector, which stops the junction from going deep into saturation. This is the idea behind 74LS and 74S logic.

    Also add a pull-down (10 kΩ base to emitter) so the transistor stays off while the GPIO is floating during reset.

    Inductive loads and the flyback diode

    Switching off a relay coil forces di/dt to be large, and V = L·di/dt can spike hundreds of volts at the collector, enough to exceed Vceo (40 V for a 2N3904) and destroy it. A diode across the coil, cathode to supply, gives the current a loop path and clamps the spike at about Vcc + 0.7 V. The trade-off is that the coil current decays slowly, so the relay releases late; a Zener in series with the diode speeds it up. The same idea reappears in MOS designs, covered in MOSFET as a switch.

    BJT vs other options

    ParameterBJT (2N3904)Logic-level MOSFET
    Control quantityBase currentGate voltage
    On-state drop0.1 to 0.3 V (fixed)I × Rds(on), can be mΩ
    Drive powerContinuous, about 10 mWAlmost none static
    Best forUnder 500 mA, low costHigh current, efficiency

    Below a few hundred milliamps, the BJT wins on price and robustness. Above that, the MOSFET's resistive on-state is better, a trade-off we explore in BJT biasing and the operating point.

    Verifying the design in simulation

    Before committing to a PCB, run a transient analysis in Cadence Spectre/Virtuoso, Siemens' Eldo or any SPICE engine. Sweep β from 50 to 300 and temperature from −40 °C to 125 °C and check that Vce stays below 0.3 V in every corner. The same corner discipline carries into IC design, and teams at Avecas apply it daily on analog blocks. For structured practice across the whole analog curriculum, see our CourseTron courses; if you want classroom-style training, ChipXpert offers instructor-led VLSI programmes.

    Key fact: a 2N3904 rated 200 mA with Vce(sat) 0.3 V at 50 mA dissipates only about 15 mW when saturated, but the same current at Vce = 6 V in the active region would dissipate 300 mW, over its 625 mW limit within a factor of two.

    Ready to go beyond single-transistor tricks? Join the CourseTron analog electronics course for guided simulations, quizzes and interview drills: explore the courses.

    Frequently asked questions

    Why design with a forced beta of 10 instead of the datasheet hFE?

    hFE is a typical active-region figure that drops with temperature, collector current and part-to-part spread. A forced beta of about 10 guarantees saturation in the worst corner and keeps Vce(sat) low.

    Why is my transistor hot even though the load works?

    Most likely it is not fully saturated, so Vce is a volt or more and P = Vce × Ic is substantial. Reduce Rb to raise Ib, then measure Vce, which should read about 0.2 V.

    Do I always need a flyback diode?

    Yes for relays, solenoids and motors. Any inductor carries current that cannot stop instantly, and without a path the collector voltage spikes until something breaks down, often the transistor itself.

    Can a BJT switch a load on the high side?

    Use a PNP, or an NPN with a level-shifting stage. A low-side NPN is simpler, and the load ground then floats near the supply when off.

    Advertisement