In this guide
How to Shift Logic Levels Between 3.3V and 5V: Dividers, MOSFETs and Shifter ICs
Short answer: a 5V output must never drive a 3.3V-only input directly — divide it down, or buffer it. A 3.3V output driving a 5V input usually needs boosting, not dividing. For one-way 5V-to-3.3V signals, a resistor divider is fine; for two-way lines such as I2C, use a MOSFET-based shifter or a dedicated IC; for fast, multi-line buses, use a proper level-shifter IC. Pick the method from the direction, the speed, and the current the line must drive — not from whichever part is in the drawer.
Your ESP32 talks at 3.3V. Your Arduino Uno, many sensors, and a pile of older modules talk at 5V. Connect a 5V output straight into a 3.3V input and the pin sees a voltage above its absolute maximum rating — typically VDD + 0.3V, so about 3.6V on an ESP32. Sometimes the board survives; sometimes the pin dies quietly, or the chip latches up and draws heavy current until something gets hot. The other direction is subtler: a 3.3V output feeding a 5V input can sit in the undefined band between "low" and "high", so the receiver reads garbage on some days and clean data on others.
This guide covers why the two voltages disagree, the three practical shifting methods — resistor dividers, the classic BSS138 MOSFET circuit, and dedicated shifter ICs — with worked numbers, and the mistakes that actually damage boards.
Why 3.3V and 5V do not mix
Every logic input decides "high" or "low" by comparing the pin voltage against two thresholds. For a CMOS input powered at VDD, the usual rule of thumb (check the datasheet — exact numbers vary by family) is:
- VIH(min), the lowest voltage guaranteed to read as high: about 0.7 × VDD
- VIL(max), the highest voltage guaranteed to read as low: about 0.3 × VDD
| Receiver supply | VIH(min) | VIL(max) | What a 3.3V output delivers |
|---|---|---|---|
| 3.3V | ~2.31V | ~0.99V | High reads cleanly |
| 5V | ~3.5V | ~1.5V | 3.3V is below VIH — marginal or failing |
That table is the whole problem in one picture. A 3.3V HIGH is comfortably above a 3.3V receiver's threshold, but below a 5V CMOS receiver's guaranteed-high threshold. Whether a 5V chip accepts 3.3V logic depends on its input family: 5V TTL-compatible inputs (VIH(min) 2.0V, as on the ATmega328P) usually accept 3.3V fine, while pure 5V CMOS inputs (VIH(min) 3.5V) do not. "It worked on my bench" is not a design rule — a 3.3V output is near the bottom of its guaranteed range (an ESP32 output high is typically around 2.64V minimum at load), and temperature, supply droop, and load can push it under the threshold on the day that matters.
In the other direction the failure is absolute, not marginal: a 5V signal into a 3.3V-only pin exceeds the pin's absolute maximum rating. Some pins are labelled 5V-tolerant — their input structure can accept 5V even when the chip runs at 3.3V — but tolerance is a per-pin, per-chip datasheet property, never an assumption. ESP32 GPIOs are not 5V-tolerant. Many STM32 pins are, but only the ones marked FT (five-volt tolerant) in the datasheet. Always check.
Two more facts before choosing a method: logic level is not supply voltage — a chip running at 3.3V can have 5V-tolerant inputs, and a 5V chip can accept 3.3V inputs if its VIH is low enough, so read the input thresholds, not the supply rail. And an output drives a voltage while an input reads one, so every fix is judged at the receiving pin.
Method 1: resistor divider — simple, one-way only
A voltage divider drops a 5V signal to 3.3V using two resistors. It works in one direction only (5V down to 3.3V), for digital signals driven push-pull, and it costs nothing.
Worked example: 5V to 3.3V
The divider formula is Vout = Vin × R2 / (R1 + R2), with R1 on top (toward 5V) and R2 to ground.
Choose R1 = 1 kΩ, R2 = 2 kΩ:
- Vout = 5 × 2000 / 3000 = 3.33V — safely inside the 3.3V receiver's range
- Current through the divider: 5V / 3000 Ω = 1.67 mA — a small, constant drain whenever the line is high
- Power: about 2.8 mW in R1 and 5.6 mW in R2 — ordinary quarter-watt resistors are fine
- Output impedance: R1 in parallel with R2 = 667 Ω
That output impedance is the number that decides speed. The divider output must charge the receiver pin's input capacitance (typically 5–10 pF) through 667 Ω, giving an RC time constant of about 6.7 ns with a 10 pF load — fast enough for UART at 115200 baud (bit period 8.7 µs) and for SPI clocks up to several MHz.
When a divider fails
- Too-high resistor values. A 10 kΩ / 20 kΩ divider gives the same 3.33V but an output impedance of 6.67 kΩ. With a 50 pF load (a long wire plus a few inputs), the rise time grows to roughly 730 ns — fine for slow UART, marginal for a 1 MHz SPI clock, and a source of flaky reads that look like software bugs.
- Bidirectional lines. A divider cannot carry a signal back the other way. On an I2C line the 3.3V side can never pull the 5V side low through the divider. Never use a divider on SDA or SCL.
- Driving a load. If the receiving pin draws current (an LED, a base resistor, a low-impedance input), the divider ratio changes because the load sits in parallel with R2. Dividers feed high-impedance logic inputs only.
- The 3.3V-to-5V direction. A divider only reduces voltage. It cannot boost 3.3V up to 5V.
A quick check in Python before you solder:
vin, r1, r2 = 5.0, 1000.0, 2000.0
vout = vin * r2 / (r1 + r2)
print("Vout:", round(vout, 2), "V") # 3.33 V
print("Current:", round(vin / (r1 + r2) * 1000, 2), "mA") # 1.67 mA
Rule of thumb: keep the divider current around 1–2 mA (low enough to ignore, high enough that stray capacitance does not dominate), and verify the divided voltage with a multimeter before connecting it to the microcontroller. The voltage dividers guide covers loading errors in more depth, and the multimeter guide covers trustworthy measurement technique.
Method 2: the MOSFET bidirectional shifter — the classic two-way circuit
The circuit on nearly every "4-channel level shifter" breakout board is one N-channel MOSFET per line, usually a BSS138, with a pull-up resistor on each side. It shifts in both directions automatically, with no direction pin — exactly what open-drain buses such as I2C need.
How it works
- The MOSFET gate is tied to the 3.3V rail. Its source connects to the 3.3V-side signal, its drain to the 5V-side signal. Each side has a pull-up resistor to its own supply rail (typically 10 kΩ).
- Both sides idle high: gate and source are both at 3.3V, so Vgs = 0 and the MOSFET is off; each side sits at its own supply.
- 3.3V side pulls low: source drops to 0V, Vgs becomes 3.3V, the MOSFET turns on and pulls the 5V side down to near 0V. The 5V receiver sees a clean low.
- 5V side pulls low: the body diode conducts first, dragging the source down until Vgs exceeds the threshold and the channel turns on, again pulling both sides low.
When either side releases, the pull-ups return both sides to their own supply voltages. The circuit needs both pull-ups to work — without them, the line floats and the MOSFET never switches cleanly.
Where it fits — and where it does not
Good for: I2C (its natural home), single-wire bidirectional lines, UART RX/TX pairs (one MOSFET per direction), and any open-drain signal at moderate speed.
Limits:
- Speed. The pull-ups charge the bus capacitance passively, so edges are slow. At 115200 baud UART this is invisible; at 400 kHz I2C it matters (see the pull-up maths below); at multi-MHz SPI it is the wrong tool.
- Weak drive. The MOSFET passes a low strongly but a high only through the pull-up resistor, so it cannot drive LEDs, long cables, or low-impedance loads.
- No isolation, no protection. It shifts voltage; it does not protect against overvoltage, ESD, or a shorted 5V rail. Both supplies must also be present: with the 3.3V rail off and 5V applied, the body diode can back-power the 3.3V rail through the pull-ups.
Pull-up maths for I2C
I2C rise time is set by the pull-up resistor and the total bus capacitance (wires, pins, and every device on the bus). The 10–90% rise time is roughly 2.2 × R × C, and the fast-mode (400 kHz) limit is 300 ns.
| Pull-up | Bus capacitance | Rise time (approx.) | Verdict at 400 kHz |
|---|---|---|---|
| 10 kΩ | 50 pF | ~1,100 ns | Too slow |
| 4.7 kΩ | 50 pF | ~517 ns | Still over the 300 ns limit |
| 2.2 kΩ | 50 pF | ~242 ns | Passes |
So the 10 kΩ pull-ups on a cheap breakout board are often wrong for 400 kHz I2C with real wiring. Drop to 2.2 kΩ (about 2.3 mA from 5V when the line is low — check your driver's sink capability) or shorten the bus. At 100 kHz standard mode the limit relaxes to 1000 ns, and 4.7 kΩ values are comfortable.
Method 3: dedicated level-shifter ICs — when the bus is serious
When you have several lines, high speed, or a bus that must simply work, a purpose-built IC beats a handful of discretes. The three families students meet most:
| IC | Direction | Best for | Key limitation |
|---|---|---|---|
| TXB0108 | Auto, bidirectional | Push-pull signals: SPI, UART, GPIO | Weak drive; not for open-drain I2C or long wires |
| TXS0108E | Auto, bidirectional | Open-drain: I2C, 1-Wire | Slower edges; internal 10 kΩ pull-ups are fixed |
| 74LVC245 | Unidirectional, direction pin | 8-bit parallel buses, SPI down-shift, strong drive | One direction at a time; needs a DIR signal |
TXB0108 — the auto-direction push-pull shifter
The TXB0108 has eight channels that sense direction automatically using one-shot edge accelerators. It suits SPI and UART lines between a 3.3V MCU and 5V peripherals, and banks of GPIO. Its weakness is drive strength: the outputs are weak by design, so it cannot drive capacitive loads, long cables, or anything that draws real current. It also has no pull-ups and cannot handle open-drain signals — a TXB on an I2C bus is the single most common "it almost works" mistake in student projects.
TXS0108E — the open-drain specialist
The TXS0108E is the sibling designed for I2C and other open-drain lines, with internal 10 kΩ pull-ups on both sides. Its edges are slower than the TXB's, which is fine for I2C at 100–400 kHz but not for fast SPI. If your bus mixes I2C and push-pull signals, split them across a TXS and a TXB (or a 74LVC245) rather than forcing one chip to do both jobs.
74LVC245 — the strong unidirectional workhorse
The 74LVC245 is an 8-bit bus transceiver: eight lines in one direction, flipped by a direction pin, with an output-enable pin. Powered at 3.3V, its inputs are 5V-tolerant, so it down-shifts 5V to 3.3V with a strong ±24 mA (typical) drive — enough for long traces, multiple loads, and a fast SPI clock. It does not auto-detect direction, so each direction needs its own chip (or a direction signal you control). For SPI, that means one 74LVC245 for MOSI, SCK and CS, and a separate boost for MISO (3.3V up to 5V).
Always read the datasheet's absolute-maximum and recommended-operating tables before wiring — the datasheet reading guide shows which numbers actually matter.
Protocol specifics: I2C, SPI, and UART
I2C — open-drain both ways, so the shifter must be bidirectional
Both SDA and SCL are pulled high and driven low by whichever side is talking. That rules out dividers and unidirectional buffers entirely. Use a MOSFET shifter or a TXS0108E, with pull-ups on both sides of the shifter, sized from the rise-time maths above. One trap: pull-ups on only the 5V side leave the 3.3V side floating when the MOSFET is off. Also note that many sensor breakout boards already include pull-ups — a second set in parallel halves the effective resistance, usually harmless at 100 kHz but worth knowing at 400 kHz.
SPI — four unidirectional lines, two in each direction
SPI is easier because every line has a fixed direction: MOSI, SCK and CS go from controller to peripheral; MISO goes back:
- MOSI, SCK, CS (5V controller → 3.3V peripheral): divider, 74LVC245, or TXB0108.
- MISO (3.3V peripheral → 5V controller): this is the line students forget. A 3.3V MISO into a 5V CMOS input may sit below VIH. Fix it with a TXB0108 channel, a 74LVC245 run in the other direction, or a single transistor/MOSFET boost stage — not a divider, which can only go down.
If the controller is 3.3V and the peripheral is 5V, the directions flip, but the rule is the same: shift every line that crosses the voltage boundary.
UART — two crossed lines, each one-way
UART TX on one side feeds RX on the other, so each direction is its own one-way channel: the 5V TX into the 3.3V RX gets a divider or buffer, and the 3.3V TX into the 5V RX gets a boost stage or a TXB0108 channel. A MOSFET shifter board handles both lines (one channel each) and is the usual student choice. At 115200 baud the bit period is 8.7 µs, so even a 500 ns rise time is a small fraction of one bit.
Current drive and speed limits
Level shifting is about voltage, but the circuit also has to deliver the signal intact.
- Dividers deliver nothing — high-impedance inputs only. Speed limit: output impedance against load capacitance (about 7 ns per 10 pF with 1 kΩ/2 kΩ values).
- MOSFET shifters deliver a strong low and a weak, pull-up-driven high. Speed limit: the pull-up resistor against bus capacitance; lower-value pull-ups mean faster edges but more current when the line is low.
- TXB0108 delivers weak drive with fast edges for short traces. Keep traces short and loads light.
- 74LVC245 delivers strong drive (±24 mA typical) — the right answer when the line fans out to several inputs or runs across a board.
As a sanity check after wiring any shifter, measure the received waveform if you can borrow an oscilloscope. Without one, send a known data pattern (a counter over UART, a register read over I2C) and look for intermittent errors that appear only at speed or with long wires: those are edge-rate problems, not code problems.
Six mistakes that damage boards or waste days
- Feeding 5V straight into a 3.3V-only pin. The classic one. ESP32 GPIOs are not 5V-tolerant; the pin's absolute maximum is about 3.6V. It may survive once and die on demo day.
- Using a TXB0108 on an I2C bus. The TXB cannot handle open-drain signals. The bus half-works, reads flake out, and the fault looks like a sensor problem. Use a TXS0108E or a MOSFET shifter for I2C.
- Putting a divider on a bidirectional line. SDA with a divider in series means the 3.3V side can never pull the 5V side low. The bus locks up or returns garbage.
- Forgetting the MISO line on SPI. MOSI, SCK and CS get shifted, MISO gets wired direct, and the 5V controller reads a marginal 3.3V signal that fails at temperature extremes or with a weak peripheral.
- Relying on the input clamp diodes. Some chips tolerate a small current through their internal protection diodes, and a series resistor can in theory keep that current small. Most student MCUs do not guarantee a clamp-current rating, so this is not a design technique — it is a hope.
- Mixing up the MOSFET shifter's sides. The BSS138 board's low-voltage side must face the 3.3V rail and the high-voltage side the 5V rail, with the gate tied to 3.3V. Reversed, the gate sits at 5V and the MOSFET never switches properly. Label the sides before wiring.
Frequently asked questions
Can I just use a resistor divider for everything?
No. Dividers work for one-way 5V-to-3.3V signals into high-impedance inputs. They cannot boost 3.3V to 5V, cannot do bidirectional lines, and cannot drive a load. I2C and any 3.3V-to-5V path need a different method.
Is it safe to connect a 3.3V output directly to a 5V Arduino input?
Usually yes for the ATmega328P, because its TTL-compatible inputs accept 2.0V as high. But it is not guaranteed for all 5V chips — pure 5V CMOS inputs need about 3.5V. Check the receiver's VIH(min), and use a shifter if you need a guarantee.
Why does my I2C sensor work at 100 kHz but fail at 400 kHz?
Almost always rise time: the pull-up resistor is too large for the bus capacitance, so the rising edge is still climbing when the next clock edge arrives. Drop the pull-ups toward 2.2 kΩ or shorten the bus (use the 2.2 × R × C estimate above).
Can a level shifter power my 3.3V circuit from 5V?
No. A level shifter passes signals, not power. The 3.3V side needs its own regulator or supply rail; a shifter board's 3.3V pin is a reference for the gate and pull-ups, not a power output.
Do I need to shift every pin between a 5V sensor and a 3.3V MCU?
Every signal line that crosses the boundary, yes — including interrupt lines, reset lines, and chip-selects, not just the data bus. Power and ground are shared, not shifted.
My sensor board says "5V tolerant" — do I still need a shifter?
If the board genuinely includes shifting or 5V-tolerant inputs (check its schematic, not the shop listing), you can connect directly. Many listings claim tolerance loosely; verify against the board's own documentation first.
Limitations
- This guide covers logic-level shifting for digital signals between 3.3V and 5V. It does not cover analogue signal scaling, power conversion, or isolation (optocouplers and digital isolators are a separate topic for high-voltage or noisy environments).
- All threshold and drive figures quoted are typical values for common logic families — always confirm against the datasheet for your specific chips, since VIH, VIL, and drive current vary by family and manufacturer.
- High-speed buses above a few MHz, long cable runs, and systems with more than two rails need a proper signal-integrity review; the methods here are sized for bench and prototype work, not production hardware.
Where to go from here
- Voltage Dividers: When They Fail and Why — the loading errors that break divider-based shifting.
- I2C vs SPI vs UART Protocols Explained — the bus fundamentals behind the protocol-specific advice above.
- Reading Datasheets Effectively — find VIH, VIL, and absolute-maximum ratings fast.
- How to Use a Multimeter for Circuit Debugging — verify your divided and shifted voltages before trusting them.
- More electronics fundamentals in the Electronics / E&TC branch hub.
Need this built for your project?
If you are wiring a mixed-voltage project — sensors, displays, and a microcontroller that disagree about 3.3V and 5V — Projectech builds it for you, with the level shifting, wiring, and firmware done and tested. Message us on WhatsApp at wa.me/918275719193 with your project details (board, sensors, and what each part runs at), and we will reply with a quotation stating the scope, price, and delivery timeline.