Logic Level Shifting Between 3.3 V and 5 V: Dividers, MOSFET Shifters, and TXS vs TXB Chips
Connecting a 3.3 V microcontroller to a 5 V sensor can fail silently or damage a pin. Learn how to check input thresholds, size pull-ups, and pick between a divider, an HCT buffer, a BSS138 shifter, or an auto-direction IC.
Most modern microcontrollers and single-board computers run their I/O at 3.3 V, while plenty of sensors, displays, relay boards and older chips still expect 5 V. Wiring the two together directly sometimes works, sometimes works until the weather changes, and sometimes slowly cooks a GPIO pin. A level shifter sits between the two voltage domains and makes each side see signals it was designed for.
There is no single best level shifter. A resistor divider, a buffer chip, a discrete MOSFET and an auto-direction translator IC each solve a different version of the problem, and each fails in its own characteristic way. This guide explains how to tell whether you need one at all, then walks through the options in order of complexity.
Two separate problems hiding in one wire
A mismatched signal can be wrong in two directions. When a 5 V output drives a 3.3 V input, the danger is overvoltage: unless the receiving pin is explicitly rated as 5 V tolerant, current flows through its protection diodes into the 3.3 V rail, which can damage the pin or lift the whole supply. When a 3.3 V output drives a 5 V input, nothing burns, but the high level may sit below what the receiver considers a valid logic 1, so the signal is read as noise or as a permanent low.
Whether the second case is a problem depends entirely on four numbers from the datasheets of the two parts involved:
- VOH: the lowest voltage the driver guarantees when it outputs a high, at a stated load current.
- VOL: the highest voltage the driver guarantees when it outputs a low.
- VIH: the minimum input voltage the receiver promises to read as a high.
- VIL: the maximum input voltage the receiver promises to read as a low.
A link works reliably only when VOH is above VIH and VOL is below VIL, with some margin left for noise and ground offsets. Classic 5 V CMOS inputs set VIH at roughly 70 percent of the supply, about 3.5 V, which a 3.3 V output can never reach. Inputs built to TTL-compatible thresholds are different. Texas Instruments' CD74HCT125 datasheet, for example, lists a minimum VIH of 2 V and a maximum VIL of 0.8 V while running from a 4.5 V to 5.5 V supply, so a healthy 3.3 V output clears it comfortably.
Worked example: checking margins and pull-up rise times
The arithmetic is simple enough that it is worth scripting, so you can paste in the real numbers from your parts instead of guessing. The script below compares a 3.3 V driver against two kinds of 5 V input, then estimates how fast an open-drain line rises with different pull-up resistors, which matters later for MOSFET shifters and I2C.
# Level-compatibility and pull-up sanity check.
# Replace the numbers with values from your own datasheets.
INPUTS = {
"5V CMOS input": {"vih": 0.7 * 5.0, "vil": 0.3 * 5.0},
"5V HCT input": {"vih": 2.0, "vil": 0.8},
}
def check(voh, vol, name, inp):
high = voh - inp["vih"]
low = inp["vil"] - vol
verdict = "OK" if high > 0 and low > 0 else "FAIL"
print(f"{name}: high margin {high:+.2f} V, low margin {low:+.2f} V -> {verdict}")
# A 3.3 V output that sags to 2.9 V under load and pulls down to 0.4 V.
for name, inp in INPUTS.items():
check(2.9, 0.4, name, inp)
def rise_10_90(r_ohms, c_farads):
# An RC edge needs ln(9), about 2.2 time constants, to go from 10% to 90%.
return 2.2 * r_ohms * c_farads
for r in (10_000, 4_700, 2_200):
t_ns = rise_10_90(r, 100e-12) * 1e9
print(f"{r / 1000:.1f} kOhm pull-up, 100 pF bus -> {t_ns:.0f} ns rise")
# Current the driver must sink to hold the line at 0.4 V against the pull-up.
sink_ma = (5.0 - 0.4) / 2_200 * 1000
print(f"2.2 kOhm to 5 V: driver sinks {sink_ma:.2f} mA")
Running it prints the following. The CMOS input fails on the high side by more than half a volt even though the low side is fine, while the HCT input passes both checks. The rise-time lines show why a 10 kΩ pull-up that is perfectly adequate for a slow button becomes a bottleneck on a bus with 100 pF of wiring and pin capacitance.
5V CMOS input: high margin -0.60 V, low margin +1.10 V -> FAIL
5V HCT input: high margin +0.90 V, low margin +0.40 V -> OK
10.0 kOhm pull-up, 100 pF bus -> 2200 ns rise
4.7 kOhm pull-up, 100 pF bus -> 1034 ns rise
2.2 kOhm pull-up, 100 pF bus -> 484 ns rise
2.2 kOhm to 5 V: driver sinks 2.09 mA
Smaller pull-ups give faster edges but force every driver on the line to sink more current, so the right value is a trade-off you check against the sink limits in your device datasheets and the bus specification.
Option 1: a resistor divider for 5 V down to 3.3 V
For a signal that only ever travels from a 5 V output to a 3.3 V input, such as a sensor's TX line feeding a microcontroller's RX pin, two resistors are often enough. With 1 kΩ in series from the 5 V output and 2 kΩ from the 3.3 V input to ground, the input sees 5 × 2 / 3, about 3.33 V. The approach has clear limits:
- It works in one direction only and cannot raise a 3.3 V signal.
- The divider resistance and the input capacitance form a low-pass filter, so large resistor values smear fast edges; keep them low for anything above a few hundred kilohertz.
- It draws current continuously whenever the line is high.
- It is useless on open-drain buses, where the line must be pulled up on both sides.
Option 2: a buffer powered from the higher rail
When a 3.3 V output must drive a 5 V input in one direction, a buffer from an HCT-style family, powered at 5 V, is the cleanest fix. Its TTL-compatible input accepts the 3.3 V high, and its output swings a full 5 V with real drive strength. This is the standard way to drive long cables, LED strips that need a crisp 5 V data line, or several 5 V inputs from one pin. It does not work in reverse and it adds a few nanoseconds of delay, which rarely matters.
Option 3: the single-MOSFET bidirectional shifter
The cheap breakout boards sold as bidirectional level shifters use one small N-channel MOSFET per line, typically a BSS138. The gate is tied to the low-voltage rail, the source connects to the low-voltage signal, the drain connects to the high-voltage signal, and each side has its own pull-up resistor to its own rail, commonly 10 kΩ. Its behavior falls into three cases:
- Nobody pulls low: the source sits at the low rail, the gate-to-source voltage is zero, the transistor is off, and each pull-up holds its side high at its own voltage.
- The low side pulls low: the gate-to-source voltage rises to the full low rail, the transistor turns on, and the high side is dragged down through the channel.
- The high side pulls low: the MOSFET's body diode conducts first and pulls the source down until the gate-to-source voltage is large enough to switch the channel fully on, and then both sides read low.
Because nothing actively drives the line high, rising edges are only as fast as the pull-up resistors can charge the wiring, which is exactly what the rise-time numbers in the script estimate. The done. land guide to these modules positions them for buses up to about 400 kHz and recommends against them for SPI, fast UART or LED data. It also warns about a subtler trap: if only one side is powered, current can leak through the body diode and partially power the other side, so these boards suit designs where both rails always come up together.
Option 4: auto-direction translator ICs
Translator chips that figure out direction by themselves come in two families from Texas Instruments that look similar on paper and behave very differently in practice.
TXS parts: pass transistors with edge accelerators
The TXS0104 and TXS0108E work much like the discrete MOSFET circuit, with internal pull-ups and one-shot circuits that briefly boost each transition. TI's product page for the TXS0108E gives an A-side supply of 1.4 V to 3.6 V, a B-side supply of 1.65 V to 5.5 V, and rates of up to 110 Mbps push-pull but only 1.2 Mbps open-drain. A detailed bench comparison on the Big Mess o' Wires blog found the eight-channel part touchy: its one-shots stay active for roughly 30 ns, and long wires, connectors or extra capacitance can retrigger them and cause oscillation. The same write-up found the four-channel TXS0104, rated for 2 Mbps open-drain, much more forgiving of longer wiring.
TXB parts: buffered, but with deliberately weak outputs
The TXB0104 contains real output buffers and senses direction automatically, which makes it fast for push-pull signals. To let either side take over, its outputs are intentionally weak, so an external pull-up fights them. In the example discussed in that same comparison, a weak output with about 4 kΩ of effective series resistance against a 10 kΩ pull-up to 5 V only gets the line down to roughly 1.4 V, which is no longer a valid low for many inputs. TXB parts therefore belong on short point-to-point push-pull links such as SPI, never on I2C or anything with pull-ups.
Comparison at a glance
- Resistor divider: one direction, 5 V down to 3.3 V only, nearly free, slow with large resistors, wastes a little current.
- HCT buffer at 5 V: one direction, 3.3 V up to 5 V, strong output, fast, good for cables and LED data.
- BSS138 MOSFET shifter: bidirectional, open-drain friendly, inexpensive, speed limited by pull-ups, needs both rails powered.
- TXS-family IC: bidirectional, handles open-drain and push-pull, sensitive to wire length and capacitance, especially the eight-channel version.
- TXB-family IC: bidirectional push-pull only, fast on short traces, breaks with pull-up resistors and weak drivers.
Common mistakes
- Assuming a pin is 5 V tolerant because a forum post said so, rather than checking the absolute maximum ratings for that exact pin and package.
- Putting a TXB translator on an I2C bus, where the pull-ups overpower its weak outputs.
- Leaving the pull-ups on every breakout board in place, so several kilohm-scale resistors in parallel exceed what the drivers can sink.
- Running a MOSFET shifter with one side unpowered and wondering why a sleeping sensor stays half awake.
- Using an eight-channel TXS module on a long ribbon cable and debugging what looks like software corruption but is ringing.
Decision checklist
- Read VOH, VOL, VIH and VIL for both parts; if the margins pass and no input sees more than its rated maximum, skip the shifter.
- If the signal only goes from 5 V to 3.3 V and is slow, use a divider.
- If it only goes from 3.3 V to 5 V, or must drive a cable, use an HCT-style buffer powered at 5 V.
- If it is an open-drain bus like I2C at standard speeds, use a BSS138 circuit or a TXS0104, and size the pull-ups with a rise-time estimate.
- If it is a fast bidirectional push-pull link on short traces, consider a TXB part or a direction-controlled translator.
- Whatever you choose, look at the real edges with an oscilloscope before trusting the design.
Level shifting looks like a solved problem because the breakout boards are cheap and plentiful, but each board quietly assumes a signal type, a speed and a wiring length. Matching those assumptions to your actual circuit is what turns an intermittent prototype into one that works every time it powers up.
Enjoyed this?
Get the next deep dive in your inbox. No spam — just the stories worth reading.
Subscribe to the newsletter