A logic gate is a tiny electronic circuit that takes one or more binary inputs (0 or 1) and produces a single binary output based on a fixed rule, such as AND, OR, or NOT. Billions of them work together inside every computer, phone, and smart device to make decisions, do math, and store data.
This guide explains how a logic gate works, covers all seven standard types with truth tables, shows how gates become adders and memory, and gives you a small circuit to build. It also covers the mistakes that trip up beginners, which most explanations skip.
Key takeaways
- A logic gate turns binary inputs into one binary output using a fixed rule.
- There are seven standard gates: AND, OR, NOT, NAND, NOR, XOR, and XNOR.
- Think of AND as switches in series and OR as switches in parallel.
- A truth table lists the output for every possible input combination.
- NAND and NOR are “universal”: either one can build every other gate.
- Gates are built from transistors, and a modern processor contains billions of them.
What is a logic gate?
A logic gate is the smallest decision-making unit in digital electronics. It looks at its inputs, applies one rule, and outputs a 1 (true, or “high”) or a 0 (false, or “low”).
Inside a real chip, 0 and 1 aren’t magic numbers. They’re voltage ranges. In classic 5 V TTL chips, an input below about 0.8 V reads as 0, and an input above about 2.0 V reads as 1. In common 74HC CMOS chips, roughly the bottom 30% of the supply voltage reads as 0 and the top 30% reads as 1.
The zone in between is undefined. That detail explains a beginner mistake covered below: leaving an input unconnected.
What’s the easiest way to picture a logic gate?
Picture a lamp wired to a power source through switches. Closed means 1, open means 0, and the lamp is the output.
AND = switches in series OR = switches in parallel
+5 V ──[ A ]──[ B ]──( lamp ) +5 V ──┬──[ A ]──┬──( lamp )
└──[ B ]──┘
- AND: The lamp lights only if both switches are closed, because current has to pass through both.
- OR: The lamp lights if either switch is closed, because current can take either path.
- NOT: A normally closed switch. Pressing it breaks the circuit, so a 1 in gives a 0 out.
Early computers worked this way, using electromechanical relays as the switches. Modern gates do the same job with transistors.
What are inputs, outputs, and truth tables?
- Inputs: The signals going into the gate, usually labeled A and B.
- Output: The single result, usually labeled Y or Q.
- Truth table: A chart listing the output for every possible input combination.
Because every input is 0 or 1, the number of rows in a truth table is 2 raised to the number of inputs.
| Number of inputs | Rows in the truth table |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | 8 |
| 4 | 16 |
| 8 | 256 |
How does a logic gate work?
Under the hood, a gate is a small group of transistors acting as switches. Here is the sequence for a CMOS NAND gate, the most common building block.
- The inputs arrive as voltages, high or low.
- Those voltages turn the gate’s transistors on or off.
- Two transistors in parallel connect the output to the supply voltage, and two in series connect it to ground.
- The output is pulled low only when both inputs are high. In every other case, it’s pulled high.
- That output voltage feeds the next gate, which repeats the process.
Each step takes only a few nanoseconds, which is why chains of millions of gates can do their work billions of times per second.
What are the types of logic gates?
There are seven standard logic gates. AND, OR, and NOT are the basic gates. NAND and NOR are the universal gates. XOR and XNOR are the exclusive gates. Some lists also count the buffer, which passes its input through unchanged, as an eighth.
| Gate | Output is 1 when… | Boolean expression | Everyday way to think of it |
|---|---|---|---|
| AND | Every input is 1 | Y = A · B | Both switches must be on |
| OR | At least one input is 1 | Y = A + B | Any one switch is enough |
| NOT | The input is 0 | Y = Ā | A flip: yes becomes no |
| NAND | Not every input is 1 | Y = (A · B)′ | An AND, flipped |
| NOR | Every input is 0 | Y = (A + B)′ | An OR, flipped |
| XOR | The inputs are different | Y = A ⊕ B | Exactly one switch is on |
| XNOR | The inputs are the same | Y = (A ⊕ B)′ | A match detector |
AND, OR, NAND, and NOR also come with three, four, or more inputs. The rule scales: a 3-input AND outputs 1 only when all three inputs are 1.
What does the combined truth table look like?
For two inputs, here are all six two-input gates side by side. A NOT gate has one input: 0 gives 1, and 1 gives 0.
| A | B | AND | OR | NAND | NOR | XOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
What is a real-world example of each gate?
- AND: A garage door closes only if the button is pressed and the safety beam is clear.
- OR: A car’s dome light comes on if any door is open.
- NOT: An indicator that lights when a door switch is not triggered.
- NAND: A warning light that stays on unless every safety check passes.
- NOR: An “all clear” light that comes on only when none of the alarm inputs are active.
- XOR: Two light switches at opposite ends of a hallway, where flipping either one changes the light.
- XNOR: A circuit that checks whether two bits are equal.
How do you recognize logic gate symbols?
AND has a flat back and a rounded front, like a capital D. OR has a curved back that comes to a point. NOT is a triangle. A small circle, called a bubble, on the output means “invert,” so a NAND is an AND shape with a bubble.
A bubble on an input means the signal is active-low: it does its job when it’s 0, not 1.
What is Boolean algebra, and how does it simplify gates?
Boolean algebra is the math of true and false. Each gate has an algebra expression, and the rules let you shrink a circuit before you build it.
| Rule | Expression |
|---|---|
| Identity | A · 1 = A, and A + 0 = A |
| Null | A · 0 = 0, and A + 1 = 1 |
| Same input twice | A · A = A, and A + A = A |
| Complement | A · A′ = 0, and A + A′ = 1 |
| Double negation | (A′)′ = A |
| De Morgan’s laws | (A · B)′ = A′ + B′, and (A + B)′ = A′ · B′ |
Here is one in action. Say a circuit calculates (A · B) + (A · B′). Factor out A, and you get A · (B + B′). Since B + B′ always equals 1, the whole thing simplifies to A. Three gates collapse into a wire.
Why are NAND and NOR called universal gates?
Any digital circuit can be built from NAND gates alone, or from NOR gates alone. That’s why they’re called universal.
| To build this | From NAND gates | How many NANDs |
|---|---|---|
| NOT | Tie both inputs together | 1 |
| AND | NAND, then a NAND wired as NOT | 2 |
| OR | Invert each input with its own NAND-as-NOT, then NAND the results | 3 |
The OR trick comes from De Morgan’s law: A OR B equals NOT(NOT A AND NOT B). The same rules work in reverse for NOR.
What’s the difference between combinational and sequential logic?
- Combinational logic: The output depends only on the inputs right now. An adder is combinational. Change the inputs and the output follows.
- Sequential logic: The output also depends on stored past values. Feed a gate’s output back into its input and the circuit can hold a bit of memory.
Two cross-connected NOR gates make a basic SR latch, the simplest memory cell. Latches and flip-flops are the building blocks of registers and counters.
What are logic gates made of?
Logic gates are made of switches, and today those switches are transistors. The count depends on the gate and the design style.
| Gate | Typical transistors (CMOS) |
|---|---|
| NOT | 2 |
| NAND | 4 |
| NOR | 4 |
| AND | 6 (a NAND plus a NOT) |
| OR | 6 (a NOR plus a NOT) |
| XOR | Commonly 8 to 12, depending on the design |
This is why NAND and NOR are cheaper than AND and OR. They skip the extra inversion stage.
Diodes alone can build AND and OR gates, but not a NOT gate, so diode logic is an incomplete family. Transistors add inversion and signal gain, which is why every complete logic family relies on them.
How big can it get?
Scale shows how far this goes. The Intel 4004 processor in 1971 had 2,300 transistors. Apple’s M4 chip has about 28 billion. Many of those are in memory, but the logic is built from the same ideas.
Which logic family should you use?
A logic family is a set of gates built with the same technology, so they share voltage levels and speed. Early integrated circuits used resistor–transistor logic, then diode–transistor logic, then TTL. Today CMOS dominates.
| Family | Technology | Typical supply | What to know | Good for |
|---|---|---|---|---|
| 74LS (TTL) | Bipolar transistors | 5 V | Classic and still common in older gear; draws more power than CMOS | Repairing or matching vintage designs |
| 74HC | CMOS | 2 V to 6 V | Low power; runs from 3.3 V or 5 V | General hobby builds |
| 74HCT | CMOS with TTL-level inputs | 5 V | Accepts TTL-level signals, so it bridges families | Mixing with TTL parts |
| 4000 series | CMOS | About 3 V to 15 V on many parts | Wide supply range; slower than 74HC | Battery or higher-voltage projects |
| 74LVC | Low-voltage CMOS | About 1.65 V to 3.6 V | Fast; many parts tolerate 5 V inputs | 3.3 V microcontroller boards |
Don’t mix families blindly. Confirm each part’s voltage levels in its datasheet before you connect them.
What other gate-like parts will you see?
- Buffer: Passes its input through unchanged. It doesn’t alter the logic, but it can strengthen a weak signal so it can drive more inputs.
- Tri-state gate: Adds a third output state called high impedance, often written Z, where the output is effectively disconnected. This lets many devices share one wire, as long as only one drives it at a time.
- Schmitt trigger: An input with two different switching thresholds, one for rising signals and one for falling. It cleans up slow or noisy signals, such as a bouncing button. The 74HC14 is a common example.
What can you build with logic gates?
Gates combine into circuits that do useful work.
- Adders: Add binary numbers.
- Comparators: Check whether two numbers match.
- Multiplexers: Pick one of several inputs.
- Latches and flip-flops: Store a bit of memory.
- Counters: Count clock pulses.
How does a half adder work?
A half adder adds two single bits. The sum bit is an XOR of the inputs, and the carry bit is an AND of the inputs.
| A | B | Sum (A XOR B) | Carry (A AND B) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Look at the last row: 1 + 1 equals binary 10, which is sum 0 and carry 1. A full adder chains two half adders and an OR gate to also accept a carry from the previous bit. Chain eight of them and you have an 8-bit adder.
How do logic gates relate to programming?
Every programming language has operators that work like gates. The key detail is the difference between logical and bitwise versions.
| Gate | Logical operator (Python / C-style) | Bitwise operator |
|---|---|---|
| AND | and / && | & |
| OR | or / || | | |
| NOT | not / ! | ~ |
| XOR | No direct logical operator (use != on booleans) | ^ |
Bitwise operators apply the gate to every bit at once. For example, 5 is 0101 and 3 is 0011, so 5 & 3 is 1, 5 | 3 is 7, and 5 ^ 3 is 6. That’s eight gates’ worth of work, done in one instruction.
How do you build a simple logic gate circuit?
This beginner build uses a 74HC08 AND chip to prove the truth table with your own hands. The pin numbers follow the standard 74HC08 pinout, so check them against your datasheet.
Parts:
- One 74HC08 quad AND chip
- A breadboard and jumper wires
- A regulated 5 V supply, such as a USB breakout
- Two push buttons
- Two 10 kΩ resistors
- One LED and one 1 kΩ resistor
- One 0.1 µF capacitor
Steps:
- Place the chip across the breadboard’s center gap.
- Connect pin 14 to +5 V and pin 7 to ground. Add the 0.1 µF capacitor between them, close to the chip.
- Wire each button so one side goes to +5 V and the other side goes to a gate input, pins 1 and 2.
- Add a 10 kΩ resistor from each input pin to ground. This pull-down keeps the input at 0 until you press the button.
- Connect output pin 3 through the 1 kΩ resistor to the LED’s longer leg. Connect the LED’s shorter leg to ground.
- Tie the unused gate inputs (pins 4, 5, 9, 10, 12, and 13) to ground.
- Power it up. The LED lights only when you hold both buttons.
Swap in a 74HC32 (OR) or 74HC86 (XOR). They use the same pin layout, so you can rerun the experiment and compare results with the truth table.
No parts? Free browser simulators such as CircuitVerse and Falstad’s circuit simulator let you try the same thing with virtual gates.
What mistakes do beginners make with logic gates?
- Mixing up OR and XOR. OR is true when one or both inputs are 1. XOR is false when both are 1.
- Reading NAND and NOR as AND and OR. The “N” flips the output, so the truth table is the opposite.
- Leaving inputs floating. An unconnected CMOS input can pick up noise and flip randomly. Tie unused inputs to ground or the supply voltage.
- Skipping the pull-down or pull-up resistor. A button that isn’t pressed shouldn’t leave the input undefined.
- Ignoring power-pin capacitors. A 0.1 µF capacitor near each chip’s power pins smooths the supply and prevents odd glitches.
- Mixing voltage levels. Feeding a 5 V signal into a 3.3 V chip that isn’t rated for it can damage the chip.
- Forgetting propagation delay. Every gate takes a few nanoseconds to respond. When two paths of different lengths meet, the output can briefly glitch before it settles.
- Overloading an output. The number of inputs one output can drive is called fan-out. Each added input slows the signal a little, and loads like LEDs draw real current. A 1 kΩ resistor in series with the LED keeps a typical 74HC output safe.
- Letting two outputs fight. If two tri-state outputs drive the same wire at once, the result is undefined and can overheat parts.
- Misreading active-low signals. A bubble or a name like RESET̄ means the signal acts when it’s 0.
Where did logic gates come from?
| Year | Milestone |
|---|---|
| 1854 | George Boole publishes his algebra of true and false |
| 1924 | Walther Bothe builds an early electronic AND circuit for a physics experiment, and shares the 1954 Nobel Prize in physics for the coincidence method |
| 1937 | Claude Shannon’s MIT master’s thesis shows that Boolean algebra can describe switching circuits |
| Mid-1960s | Texas Instruments’ 7400 series puts standard gates into inexpensive chips |
| 1971 | The Intel 4004 puts a full processor on one chip with 2,300 transistors |
| Today | CMOS dominates, and chips hold billions of transistors |
Where are logic gates used?
Logic gates are inside nearly everything electronic:
- Processors and graphics chips
- Memory and storage controllers
- Phones, tablets, and smartwatches
- Calculators and digital clocks
- Traffic light controllers and alarm systems
- Programmable chips like FPGAs, which rearrange gates after manufacturing
Try it yourself
Pick one gate and prove its truth table. Build the AND circuit above, or open a free simulator like CircuitVerse, drop in a gate and two switches, and test all four input combinations.
Then build the half adder from an XOR and an AND. Once you can add 1 + 1 with two gates, you understand the idea behind every processor ever made.
Frequently Asked Questions
What are the 7 basic logic gates?
The seven standard logic gates are AND, OR, NOT, NAND, NOR, XOR, and XNOR. AND, OR, and NOT are the basic gates. NAND and NOR are universal gates because either can build any other gate. XOR outputs 1 when inputs differ, and XNOR outputs 1 when they match.
What is a logic gate with an example?
A logic gate is a circuit that turns binary inputs into one binary output using a fixed rule. For example, an AND gate in a garage-door opener could output 1, meaning close the door, only when the remote button is pressed and the safety sensor is clear. If either input is 0, the output stays 0.
Why are NAND and NOR called universal gates?
Because you can build every other gate, and therefore any digital circuit, from NAND gates alone or from NOR gates alone. A NOT gate is a NAND with its inputs tied together, and AND and OR follow from there. Designers value this because a single repeatable building block keeps designs simple.
What is the difference between a logic gate and a transistor?
A transistor is a tiny electronic switch. A logic gate is a small group of transistors wired together to perform a logical rule. In common CMOS designs, a NOT gate uses two transistors, and a NAND gate uses four. Billions of transistors, grouped into gates, make up a modern processor.
Do logic gates only work with 0 and 1?
Yes, at the logical level. Inside the circuit, 0 and 1 are voltage ranges, not exact values. In a 5 V TTL chip, an input below about 0.8 V reads as 0 and above about 2.0 V reads as 1. Voltages in between are undefined, which is why floating, unconnected inputs can cause erratic behavior.
Sources and how this guide was checked
Definitions, history, and chip counts were checked against the pages below. Voltage thresholds and logic-family traits are standard datasheet-level values and vary by part, so confirm them for your exact chip. The breadboard circuit follows the standard 74HC08 pinout but has not been bench-tested by us.