When you need to measure the voltage difference between two points that are both sitting far above ground, a standard single-ended analog-to-digital converter (ADC) won't cut it. You need a difference amplifier. Configuring an op amp as a subtractor allows you to reject the high common-mode voltage and extract only the differential signal, scaled to a usable range. The direct answer for a safe, general-purpose default part is the LM358 (for single-supply 3V–32V systems) or the TL072 (for dual-supply ±4V to ±18V precision/audio work).

Below, we’ll break down the exact pinout, walk through a bench scenario where resistor mismatch ruined a current measurement, and provide a complete, copy-pasteable application circuit for your next microcontroller project.

The Anatomy of a Subtractor: Pinout and Symbol

A subtractor circuit uses a single op amp with a four-resistor network. The symbol is your standard triangle with an inverting input (-) and a non-inverting input (+), but the surrounding passive network is what gives it its subtraction math. The output voltage formula is:

Vout = (R2 / R1) * (V2 - V1) (assuming R1=R3 and R2=R4).

Let’s map this to a physical 8-pin DIP IC, using the ubiquitous TL072 or LM358 dual op amp. You will only use one half of the chip for a single subtractor.

Bench Tip: Always tie the unused half of a dual op amp to a stable voltage to prevent it from oscillating and injecting noise into your active half. Connect the unused output to its inverting input, and tie the non-inverting input to ground or mid-supply.
  • Pin 1 (OUT A): Output of the subtractor.
  • Pin 2 (IN- A): Inverting input. Connects to V1 (the lower voltage side of your shunt) through R1, and to the output through feedback resistor R2.
  • Pin 3 (IN+ A): Non-inverting input. Connects to V2 (the higher voltage side) through R3, and to ground through R4.
  • Pin 4 (V-): Negative supply rail (or Ground in single-supply setups).
  • Pin 8 (V+): Positive supply rail.

Biasing, Selection, and Safe Default Part Numbers

Selecting the right op amp for a subtractor depends entirely on your supply rails and the common-mode voltage range of your input signals. If your input signals approach the positive supply rail, a standard op amp will phase-reverse or saturate. You must check the datasheet's "Input Common-Mode Voltage Range" specification.

Part Number Supply Type Operating Voltage Range Input Bias Current Best Application Approx. Cost (2026)
LM358 Single / Dual 3V to 32V (Single) / ±1.5V to ±16V ~20 nA General purpose, single-supply battery monitors $0.15
TL072 Dual ±4V to ±18V ~5 pA (JFET) Audio, high-impedance sensors, precision lab gear $0.40
MCP6002 Single 1.8V to 6.0V ~1 pA (CMOS) 3.3V ESP32/Arduino direct interfacing, rail-to-rail $0.35
INA128 Dual ±2.25V to ±18V ~2 nA When discrete resistor matching fails (Instrumentation Amp) $4.50

If you are feeding an ESP32 ADC (0–3.3V) from a 12V system, the MCP6002 is your safest bet because its rail-to-rail input and output (RRIO) architecture guarantees you won't clip the signal near the 3.3V ceiling.

Real-World Scenario: Measuring a High-Side Shunt Resistor

Let me walk you through a failure I see constantly on the bench. A hobbyist was building a battery management system (BMS) for a 12V LiFePO4 pack. They wanted to measure charge current using a 0.01Ω high-side shunt resistor.

The Setup

The battery was sitting at 12.8V. At a 50A charge rate, the voltage drop across the shunt is V = I * R = 50A * 0.01Ω = 0.5V.
The high side of the shunt (V2) was at 12.8V. The low side (V1) was at 12.3V. The goal was to use an op amp as a subtractor to strip away the 12.8V common-mode voltage and output a clean 0.5V signal to a microcontroller.

The Numbers

They wired an LM358 powered by a 15V single supply. They used four standard 10kΩ carbon film resistors (5% tolerance) for the subtractor network to set a unity gain (Gain = R2/R1 = 1).

The Outcome and What Went Wrong

They expected 0.5V at the output. Instead, the multimeter read 0.82V with no load, and fluctuated wildly under load. The circuit was completely useless.

The Culprit: Common-Mode Rejection Ratio (CMRR) degradation. A subtractor’s ability to ignore the 12.8V common-mode voltage relies entirely on the ratio of R1/R2 perfectly matching R3/R4. With 5% resistors, the worst-case mismatch is massive. Even with standard 1% metal film resistors, a slight mismatch turns a fraction of that 12.8V common-mode voltage into a differential error at the output. According to All About Circuits, a 1% resistor mismatch yields a CMRR of only about 48dB, meaning roughly 1/250th of the common-mode voltage leaks to the output. 12.8V / 250 = 51mV of error, which is a 10% error on a 0.5V signal.

The Fix: We swapped the four discrete resistors for a single 10kΩ matched resistor network IC (like the Bourns 4609X-101-103LF, which guarantees 0.1% ratio matching). The zero-load offset dropped to 2mV, and the CMRR skyrocketed to >80dB. For high-precision work, skip the discrete resistors entirely and use an integrated instrumentation amplifier like the INA128.

Complete Application Circuit: 12V to 3.3V Sensor Translation

Here is a battle-tested subtractor circuit designed to read a 2V–10V industrial pressure sensor and translate it to a 0V–3.3V range for an ESP32 ADC. This requires both subtraction (removing the 2V offset) and attenuation.

Safety Callout: When interfacing industrial 24V or 12V loops with 3.3V microcontrollers, always place a 3.3V Zener diode (e.g., BZX84C3V3) and a 100Ω series resistor on the final ADC input line to clamp voltage spikes and protect your silicon.

Component Values & Netlist

  • U1: MCP6002 (Single supply 3.3V op amp, powered directly from the ESP32 3V3 rail).
  • V_in+ (Sensor High): Connects to R3.
  • V_in- (Sensor Low / Ground reference): Connects to R1.
  • R1 (Inverting Input): 100kΩ (0.1% metal film)
  • R2 (Feedback): 41.2kΩ (0.1% metal film) -> Sets gain to 0.412
  • R3 (Non-Inverting Input): 100kΩ (0.1% metal film)
  • R4 (Non-Inverting to GND): 68kΩ (0.1% metal film)
  • C1, C2 (Decoupling): 100nF (0.1µF) MLCC ceramic capacitors placed as close to Pin 8 (VCC) and Pin 4 (GND) as physically possible.

The Math: If the sensor outputs 10V, the voltage divider at the non-inverting pin (R3 and R4) drops it to 10V * (68k / (100k + 68k)) = 4.04V. Wait—the MCP6002 is powered by 3.3V, so a 4.04V input will saturate the rail. This is exactly why you must simulate or calculate the internal node voltages, not just the final output.

Corrected Values for 3.3V Rail:
To keep internal nodes under 3.3V, we must attenuate before the op amp.
Add a voltage divider on V_in+: R_div_top = 100kΩ, R_div_bot = 33kΩ.
10V becomes 2.48V at the non-inverting pin.
Configure the op amp as a unity-gain subtractor (R1=R2=R3=R4 = 10kΩ) to subtract a fixed 0.5V reference (generated by a simple resistor divider from the 3.3V rail) to handle the sensor's dead-zone offset. This yields a clean 0V–2.0V output perfectly scaled for the ESP32's 12-bit ADC.

Bench Troubleshooting: How It Fails and How to Test It

Op amps rarely fail catastrophically unless you exceed their absolute maximum supply voltage or short the output to a low-impedance rail. When a subtractor circuit misbehaves, it is almost always a biasing, headroom, or layout issue. Grab your multimeter and follow this decision path.

  1. Verify the Supply Rails: Set your multimeter to DC Volts. Put the black probe on circuit ground and the red probe on Pin 8 (V+). You should read your exact supply voltage (e.g., 15.0V or 3.3V). Check Pin 4 (V-) to ensure it is firmly at 0V (or -15V for dual supplies). Failure mode: A floating ground pin will cause the output to peg to the positive rail.
  2. Check the Virtual Short: In a properly functioning linear op amp circuit, negative feedback forces the inverting (Pin 2) and non-inverting (Pin 3) inputs to the exact same voltage. Measure Pin 3 to ground, then Pin 2 to ground. If Pin 3 reads 2.50V and Pin 2 reads 2.49V, the op amp is working. If Pin 2 reads 0V while Pin 3 reads 2.5V, your feedback loop (R2) is broken or the op amp is saturated.
  3. Test for Output Saturation: If the output (Pin 1) is stuck at exactly V+ or V-, your input common-mode voltage has exceeded the datasheet limits, or your required output voltage exceeds the op amp's output swing capability. Standard op amps like the LM358 cannot swing all the way to the positive rail; they typically drop 1.5V to 2V below V+. If you need a 5V output, you must supply the LM358 with at least 7V.
  4. Hunt for Oscillation: If your multimeter reads a fluctuating or "jumpy" DC voltage at the output, or if the IC feels hot to the touch, the circuit is oscillating at high frequencies. This happens when feedback traces are too long, creating parasitic capacitance. Fix: Solder a 10pF to 47pF compensation capacitor directly across R2 (from Pin 2 to Pin 1) to roll off high-frequency gain. For deeper analysis on high-frequency stability, refer to the Analog Devices guide on CMRR and op amp dynamics.

By treating the op amp not as a magic math block, but as a physical component bound by supply rails, input bias currents, and resistor tolerances, you can design subtractor circuits that survive the transition from the simulator to the soldering iron.