Logic Gate Visualizer
Simulate AND, OR, NOT, XOR, NAND, NOR, and XNOR gates in real time. Click the inputs to toggle them between 0 and 1, and watch the truth table and output update instantly - no circuit-building experience required.
Click inputs on the diagram to toggle.
Truth Table
| Input A | Input B | Output |
|---|
What Are Logic Gates?
Logic gates are the fundamental building blocks of digital electronics. They are physical devices - built from transistors - that implement Boolean functions, taking one or more binary inputs (0 or 1, LOW or HIGH) and producing a single binary output based on a fixed rule.
Every digital device you own - your phone, laptop, smartwatch, router, even your microwave's control board - is, underneath all the software, a physical arrangement of billions of these microscopic switches. A modern CPU alone can contain tens of billions of logic gates on a single chip, each one following the same simple rules described below, combined into structures complex enough to run an operating system.
The reason logic gates matter for anyone studying electronics or computer engineering is that they're the bridge between two worlds: Boolean algebra (the math of true/false logic) and physical circuits (transistors, voltage, current). Once you understand how a handful of simple gates behave, you can predict - and design - the behavior of arbitrarily complex digital systems, because everything from a calculator to a CPU is just gates wired together.
How Logic Gates Work: Truth Tables
Every gate's behavior is completely described by its truth table - a list of every possible input combination and the output it produces. Because binary inputs only have two states, a 2-input gate has exactly 4 possible input combinations (2²), and a 3-input gate has 8 (2³).
AND Gate
Output is HIGH (1) only if every input is HIGH.
| A | B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Analogy: A safety interlock that needs two keys turned simultaneously - miss either one and nothing happens.
OR Gate
Output is HIGH if at least one input is HIGH.
| A | B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Analogy: A hallway light wired to two switches - flip either one and the light turns on.
NOT Gate (Inverter)
A single-input gate. Output is always the opposite of the input.
| A | Output |
|---|---|
| 0 | 1 |
| 1 | 0 |
XOR Gate (Exclusive OR)
Output is HIGH only if the inputs are different.
| A | B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
XOR is the "one but not both" gate, and it's the workhorse of binary addition.
NAND Gate (NOT-AND)
The inverse of AND. Output is LOW only when every input is HIGH.
| A | B | Output |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NOR Gate (NOT-OR)
The inverse of OR. Output is HIGH only when every input is LOW.
| A | B | Output |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
XNOR Gate (Exclusive NOR)
The inverse of XOR. Output is HIGH when the inputs match.
| A | B | Output |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Worked Example: Building a Half Adder from Gates
A great way to see why gates matter is to build the simplest piece of arithmetic hardware: a half adder, which adds two single binary digits.
Adding two bits, A and B, gives a Sum and a Carry:
| A | B | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Look closely and you'll notice:
- Sum is exactly the XOR truth table.
- Carry is exactly the AND truth table.
So a half adder is just one XOR gate and one AND gate, fed the same two inputs: Sum = A XOR B, Carry = A AND B. Chain several of these together (with a bit of extra logic for carry-in, making a full adder) and you have the arithmetic core of a CPU's ALU. This is the direct link between the truth tables above and real computing hardware.
Common Mistakes When Learning Logic Gates
- Confusing OR and XOR. OR is inclusive (1,1 → 1); XOR is exclusive (1,1 → 0). This trips up almost everyone the first time.
- Assuming NAND/NOR are just "AND/OR with a NOT symbol tacked on" and skipping past them. In practice, NAND and NOR are the gates most chips are actually built from, because they're cheaper to fabricate as transistors than AND/OR are - see the "universal gates" section below.
- Forgetting that a NOT gate only takes one input. It's the only single-input gate on this page; wiring it like a 2-input gate is a common beginner error in schematic tools.
- Mixing up active-HIGH and active-LOW logic. In real datasheets, some inputs/outputs are "active LOW," meaning 0 means "on." The truth tables here assume standard active-HIGH logic (1 = HIGH = true).
- Treating Boolean 1/0 as if it always means 5V/0V. The physical voltage that represents "1" depends on the logic family (TTL, CMOS, etc.) - the truth table is the logical behavior, independent of the actual voltage levels used.
Why NAND and NOR Are Called "Universal Gates"
A NAND gate (or a NOR gate, alone) is called universal because any other logic function - AND, OR, NOT, XOR, anything - can be built using only that one gate type, wired in different combinations. For example:
- A single NAND gate with both inputs tied together behaves as a NOT gate.
- Two NAND gates in sequence recreate an AND gate.
This matters enormously in real chip manufacturing: it's cheaper and more consistent to fabricate a chip using one repeated gate structure (NAND) than to fabricate several different gate types. That's a major reason NAND-based logic is so common in real ICs - and also why NAND flash memory (the tech inside your SSD and USB drives) borrows its name from the same gate.
When to Use Which Gate
| If you need... | Use |
|---|---|
| "Both conditions must be true" (e.g., door unlocks only if key AND code are correct) | AND |
| "Any one condition is enough" (e.g., alarm triggers if door OR window sensor trips) | OR |
| To invert a signal / create an enable-disable toggle | NOT |
| To detect when two signals differ (parity checking, binary addition) | XOR |
| To detect when two signals match (equality comparison) | XNOR |
| To build custom logic cheaply in silicon (chip design) | NAND / NOR |
Practical Applications
- ALUs (Arithmetic Logic Units): The math engine inside every CPU. Binary addition, subtraction, and comparison are all built from layered AND/XOR/OR gates, exactly as shown in the half-adder example above.
- Flip-Flops and Memory: Cross-wiring NAND or NOR gates with feedback loops creates a circuit that "remembers" a bit even after the input changes - the basis of SRAM, registers, and latches.
- Control Systems: Traffic light sequencing, elevator door-safety interlocks, and washing machine cycle logic are often handled with simple gate-level logic rather than a full microcontroller, because it's cheaper and more reliable for a fixed, unchanging task.
- Parity and Error Checking: XOR gates are used to generate parity bits in data transmission and storage, letting a system detect single-bit errors.
- Digital-to-Boolean Interfacing: Sensor circuits often use gates to combine multiple digital sensor outputs (e.g., "fire only if smoke sensor AND heat sensor both trigger") to reduce false positives.
Video Walkthrough
FAQ
Q1. What is the difference between XOR and OR?
An OR gate outputs 1 even when both inputs are 1 - that's "inclusive OR." An XOR (Exclusive OR) gate outputs 0 when both inputs are 1. In short, XOR means "one or the other, but not both," while OR means "either or both."
Q2. Are logic gates analog or digital?
Logic gates are digital components - they process discrete binary signals (0 or 1). Physically, though, they're built from analog transistors (MOSFETs) that are deliberately driven into full saturation or full cutoff, so they behave as clean digital switches rather than analog amplifiers.
Q3. Why are NAND gates called "universal"?
Because any other Boolean function - AND, OR, NOT, XOR, and so on - can be constructed using only NAND gates wired together in the right combination. This is why NAND logic is a common foundation for chip fabrication, and why NAND flash memory (used in SSDs and USB drives) is named after it.
Q4. What's the difference between a half adder and a full adder?
A half adder (one XOR + one AND gate) adds two single bits and produces a Sum and a Carry, but it can't accept a carry-in from a previous addition. A full adder extends this with an extra input for carry-in, letting adders be chained together to add multi-bit binary numbers.
Q5. Can a single gate have more than 2 inputs?
Yes. AND, OR, NAND, and NOR gates are commonly available in 3-input and multi-input versions in real ICs (e.g., a 3-input AND gate outputs 1 only if all three inputs are 1). This simulator focuses on the standard 2-input case since that covers the core logic almost everyone needs first.
Q6. What voltage represents "1" in a real circuit?
It depends on the logic family. Classic TTL logic treats roughly 2V-5V as HIGH (1) and 0V-0.8V as LOW (0), while CMOS logic families use thresholds relative to their supply voltage (e.g., roughly half of VCC as the switching point). The truth tables on this page describe logical behavior, which stays the same regardless of which voltage standard a chip actually uses.
Q7. Is a buffer gate the same as a wire?
Functionally, a buffer gate (output = input, no inversion) behaves like a wire in terms of logic level, but it's not just a wire electrically - it's used to restore signal strength/timing (drive more current, clean up a degraded signal) without changing the logical value.
Q8. How do I simulate a circuit with multiple gates, not just one?
This page is a single-gate visualizer meant for learning individual gate behavior. For wiring several gates together into a full circuit, use the Digital Logic Builder linked below.
Star Tool
Build bigger circuits. This page simulates one gate at a time - for wiring multiple gates together into adders, latches, and custom logic, try the full Digital Logic Builder.
Digital Logic Builder