Home / Learn / Electronics basics

MOSFETs explained: how to choose and use one as a switch

New to this? Read from the top. Already know the basics? Jump to Going deeper for intermediate and advanced detail.

A TO-220 MOSFET with its gate, drain and source legs labelled, switching a 12 V LED strip from a microcontroller pin, with a small heatsink
Beginner

A MOSFET is the usual way to let a microcontroller switch something big: an LED strip, a motor, a solenoid or a heater. Used well, it switches amps with almost no heat. Used badly, with the wrong part or not driven fully on, it gets hot enough to burn out. This guide explains what to look for. For the basics of switching with a transistor, start with transistors as switches.

How a MOSFET works

A MOSFET (metal-oxide-semiconductor field-effect transistor) has three terminals: gate, drain and source. The gate is insulated from the rest by a thin oxide layer, so it draws no steady current. A voltage between gate and source (VGS) creates a conducting channel between drain and source. With no gate voltage, the channel is gone and the MOSFET is off.

  • N-channel: turns on when the gate is made positive relative to the source. Used as a low-side switch between the load and 0 V. The most common choice.
  • P-channel: turns on when the gate is pulled below the source. Used as a high-side switch between the supply and the load.

A low-side switch

+12 Vloadflyback diode(motors, relays)D (drain)S (source)G0 V (common with the board)100 ΩGPIO10 kΩ
The standard N-channel low-side switch for a microcontroller.
  • The load goes between the positive supply and the drain; the source goes to 0 V.
  • The microcontroller's 0 V must be connected to the load supply's 0 V, or the gate voltage has no reference.
  • A small resistor (about 100 Ω) in series with the gate limits the current spike that charges the gate's capacitance at each switch.
  • A 10 kΩ pull-down from gate to source keeps the MOSFET off while the microcontroller is starting up and its pin is floating.
  • For motors, relays and solenoids, a flyback diode across the load protects the MOSFET from the voltage spike at switch-off (see inductors explained).

The trap: threshold voltage isn't "on"

The datasheet's gate threshold voltage, VGS(th), is where the MOSFET just starts to conduct, typically a tiny current such as 250 µA. It is not where it's fully on. What matters is the on-resistance, RDS(on), and the gate voltage it's specified at. Many common MOSFETs are specified at VGS = 10 V; driven from a 3.3 V pin they only half turn on.

So for a 3.3 V board (ESP32, Raspberry Pi, Pico), choose a logic-level MOSFET with RDS(on) specified at 2.5 V or lower. For a 5 V board, 4.5 V is fine. Or use a gate driver to give the gate a full 10 V.

How hot will it get?

A fully-on MOSFET behaves like a small resistor, so the heat is I² × RDS(on). For example, a part with 0.020 Ω on-resistance carrying 5 A dissipates 5² × 0.020 = 0.5 W. The datasheet gives a thermal resistance from junction to air; a TO-220 package with no heatsink is typically around 62 °C/W, so the junction rises to about 25 + 0.5 × 62 = 56 °C in a 25 °C room: warm, but fine.

Now drive the same part from a pin that only half turns it on, so it sits at, say, 0.5 Ω: 5² × 0.5 = 12.5 W. With no heatsink that would try to reach around 800 °C, far beyond the usual 150 or 175 °C maximum, so it fails within seconds. That's the most common MOSFET failure in maker projects.

Other things to check on the datasheet

  • VDS maximum: comfortably above your supply, with margin for spikes.
  • Continuous drain current: these headline figures are usually at a 25 °C case temperature with a perfect heatsink, so work from RDS(on) and heat instead.
  • VGS maximum: often ±20 V; exceeding it punctures the gate oxide.
  • Gate charge: matters for fast PWM, because the gate has to be charged and discharged every cycle.

The body diode

Every power MOSFET has a diode built in between source and drain, pointing from source to drain in an N-channel part. It's why a MOSFET only blocks current in one direction, and why two are needed back-to-back to switch AC or to make a battery disconnect switch that blocks both ways.

PWM: dimming and speed control

Switching the MOSFET on and off quickly with PWM controls the average power to an LED strip or DC motor. A MOSFET wastes the least power when it's fully on or fully off, so the gate should switch fast. A microcontroller pin can drive a small MOSFET at a few kilohertz; for higher frequencies or big MOSFETs, use a gate driver chip.

A MOSFET is for DC loads. Never switch mains with a bare MOSFET on a breadboard; use a certified relay module or a properly insulated solid-state relay.

Intermediate and advanced

Going deeper

Why the gate draws current only while switching

The gate is a capacitor: oxide between the gate electrode and the channel. Holding it at a steady voltage takes no current, but changing that voltage means charging or discharging the capacitance, so a pulse of current flows at each edge. At high PWM frequencies these pulses add up, which is why gate drivers exist.

Switching losses

For a brief moment during each transition the MOSFET is half on with both voltage across it and current through it, and that wastes power. The slower the edges and the higher the frequency, the bigger these switching losses get compared with the conduction loss.

High-side N-channel switching

An N-channel MOSFET has lower resistance than a P-channel of the same size, so high-power circuits often use N-channel parts on the high side too. The gate then has to go above the supply voltage, which needs a bootstrap circuit or a charge pump in a dedicated driver chip.

Sources

The main references behind this guide. Numbers we worked out ourselves, such as the code outputs, come from running the code.