Building a Transistor NOT Gate: The Essential Inverter Circuit

A transistor NOT gate (often called an inverter) is a fundamental digital logic circuit that flips a HIGH input signal to a LOW output, and a LOW input to a HIGH output. While you can buy dedicated inverter ICs like the 74HC04, building a discrete transistor NOT gate is the superior choice when you need to drive higher-current loads (like relays or motors), interface mismatched logic voltage levels, or simply minimize component count on a custom PCB.

The direct answer for a robust, 5V logic inverter is to use the 2N3904 NPN BJT (rated for 40V V_CEO and 200mA I_C). For 3.3V logic or high-impedance applications where base current draw must be minimized, the 2N7000 N-channel MOSFET (rated for 60V, 200mA) is the safe default.

Component Pinout (2N3904 TO-92 Package):
Hold the transistor with the flat side facing you and the leads pointing down.
Pin 1 (Left): Emitter (E) — Connects to Ground.
Pin 2 (Middle): Base (B) — Input signal via current-limiting resistor.
Pin 3 (Right): Collector (C) — Output node via pull-up resistor.

Component Selection and Biasing for Logic Inversion

To function as a digital logic gate, the transistor must be biased strictly as a switch. We intentionally drive the device into two extreme operating regions: Cutoff (fully OFF) and Saturation (fully ON). We avoid the active/linear region entirely, as lingering there causes logic ambiguity, slow switching times, and excessive thermal dissipation.

When selecting your base resistor (R_B), you must calculate the required base current (I_B) to guarantee saturation. The rule of thumb for switching applications is to overdrive the base by a factor of 10 relative to the theoretical minimum derived from the transistor's h_FE (DC current gain). If your collector load draws 10mA and the 2N3904 has a minimum h_FE of 100, the theoretical I_B is 0.1mA. Overdriving by 10x means you want 1mA of base current. Using Ohm's law: R_B = (V_IN - V_BE) / I_B = (5V - 0.7V) / 1mA = 4.3kΩ. A standard 4.7kΩ resistor is the perfect practical choice.

Operation Regions Table (5V System with 2N3904)

Input State V_IN (Base) Base Current (I_B) Transistor Region V_OUT (Collector) Logic Output
LOW 0V 0 mA Cutoff 5.0V HIGH
HIGH 5V ~0.91 mA Saturation ~0.2V (V_CE sat) LOW

Step-by-Step Application Circuit: 5V Logic Inverter

This circuit inverts a 5V microcontroller GPIO signal to drive an indicator LED. When the GPIO is HIGH, the LED turns OFF. When the GPIO is LOW, the LED turns ON.

Materials List:

  • 1x 2N3904 NPN Transistor
  • 1x 4.7kΩ Resistor (Base current limiter, R1)
  • 1x 1kΩ Resistor (Collector pull-up, R2)
  • 1x 330Ω Resistor (LED current limiter, R3)
  • 1x Standard 5mm Red LED
  • 5V DC Power Supply and Breadboard
  1. Ground the Emitter: Insert the 2N3904 into the breadboard. Connect Pin 1 (Emitter) directly to the ground (GND) rail.
  2. Wire the Base Input: Connect one lead of the 4.7kΩ resistor (R1) to your 5V logic input signal (e.g., Arduino Pin 8). Connect the other lead to Pin 2 (Base) of the transistor.
  3. Establish the Pull-Up: Connect the 1kΩ resistor (R2) between the 5V positive rail and Pin 3 (Collector) of the transistor. This ensures the output node is pulled HIGH when the transistor is in cutoff.
  4. Connect the Load: Connect the anode (long leg) of the LED to the 5V rail via the 330Ω resistor (R3). Connect the cathode (short leg) of the LED directly to Pin 3 (Collector). Note: The collector node now acts as a current sink when the transistor turns on.
  5. Verify and Power: Double-check the flat-side pinout orientation. Apply 5V power. Drive the input HIGH; the LED should extinguish. Drive the input LOW; the LED should illuminate.
Callout Tip: Flyback Diodes for Inductive Loads
If you replace the LED with a relay coil or a small DC motor, you must place a flyback diode (like a 1N4148 or 1N4007) in reverse parallel across the load. When the transistor switches off, the collapsing magnetic field generates a high-voltage spike that will instantly punch through the collector-emitter junction and destroy the silicon.

Failure Modes and Multimeter Testing

Transistors in switching circuits rarely fail from old age; they fail from abuse. The most common failure modes are thermal runaway (caused by insufficient base drive leaving the device in the high-dissipation linear region) and secondary breakdown from exceeding the 40V V_CEO rating or failing to use a flyback diode on inductive loads.

You can definitively test a suspected dead 2N3904 using a standard digital multimeter (DMM) set to the Diode Test mode (usually indicated by a diode symbol on the dial).

Testing Procedure (Out of Circuit)

  1. Base to Emitter: Place the red probe on the Base and black on the Emitter. You should read a forward voltage drop between 0.600V and 0.750V. Swap probes (black on Base, red on Emitter); the meter should read OL (Open Loop).
  2. Base to Collector: Place the red probe on the Base and black on the Collector. Expect the same 0.600V - 0.750V reading. Swap probes; expect OL.
  3. Collector to Emitter: Place probes across Collector and Emitter in both directions. The meter must read OL both ways. If you read a short (0.00V or a continuity beep), the internal silicon has melted and the transistor is destroyed.

For deeper theoretical context on semiconductor junctions and switching behavior, refer to the All About Circuits semiconductor textbook chapter on bipolar junction transistors, or review the official ON Semiconductor 2N3904 datasheet for exact V_CE(sat) curves.

Frequently Asked Questions

Can I use a PNP transistor like the 2N3906 for a NOT gate?

Yes, but the circuit topology and logic behavior change. A PNP transistor inverter requires the Emitter to be tied to VCC (5V) and the load connected between the Collector and Ground. Crucially, a PNP inverter is non-inverting regarding the raw voltage at the collector relative to the base drive, but it acts as a high-side switch. To achieve true logic inversion with a PNP device, you generally need a two-transistor configuration or an NPN driver stage preceding it. For 95% of hobbyist and bench applications, stick to the NPN low-side switch configuration described above.

Why does my transistor NOT gate output float when the input is LOW?

If your output voltage is drifting or floating instead of snapping cleanly to 5V when the input is LOW, you have omitted or miswired the collector pull-up resistor. When the NPN transistor is in cutoff, the collector pin is effectively disconnected from ground. Without a pull-up resistor tying the collector to VCC, the node becomes high-impedance and will float, picking up ambient electromagnetic noise. Always ensure a physical resistive path (or an active pull-up) exists between the collector and the positive supply rail.

What is the maximum switching frequency for a 2N3904 inverter?

The 2N3904 has a transition frequency (f_T) of roughly 300 MHz, but in a standard saturated switching circuit, the practical limit is much lower due to storage time and capacitive loading. When driven hard into saturation, excess minority carriers accumulate in the base region, delaying turn-off. In a standard resistor-loaded inverter, you can reliably switch at 100 kHz to 250 kHz. If you need to invert PWM signals at 1 MHz or higher, you must use a Baker clamp diode to prevent deep saturation, or switch to a high-speed logic IC like the 74LVC series.

How do I interface a 3.3V ESP32 GPIO to a 5V transistor NOT gate?

The ESP32 outputs 3.3V on its GPIO pins. If you use a standard 5V pull-up on the collector, the 2N3904 will still switch perfectly fine. The base-emitter junction only requires ~0.7V to turn on. Recalculate your base resistor for the 3.3V logic HIGH: R_B = (3.3V - 0.7V) / 1mA = 2.6kΩ. Use a standard 2.7kΩ or 3.3kΩ resistor for the base. The transistor will saturate fully when the ESP32 pin goes HIGH (3.3V), pulling the 5V collector load to ground, and cut off cleanly when the ESP32 pin goes LOW (0V). This provides a cheap, effective one-way level shifter.