Logic Gates Explained: The Building Blocks of Every Digital Circuit

Every digital device you own, from a pocket calculator to a microcontroller board, is built from one simple idea repeated millions of times: a circuit that makes a yes-or-no decision. That circuit is a logic gate. A logic gate takes one or more binary inputs, each either 0 or 1, and produces a single binary output according to a fixed rule. Combine enough gates and you get adders, memory, counters, displays and, eventually, whole computers. This guide explains all seven basic gates — AND, OR, NOT, NAND, NOR, XOR and XNOR — with truth tables, symbols, Boolean expressions, and the ways gates combine into real circuits. If you are new to electronics, start with our electronics circuits basics guide for voltage, current and resistance, then come back here: logic gates are where those fundamentals turn into decisions.

Before we look at individual gates, it helps to be clear about what 0 and 1 mean in hardware. In a digital circuit, 0 usually means a low voltage, close to the negative supply rail, and 1 usually means a high voltage, close to the positive supply rail. The exact voltages depend on the logic family and the supply voltage of the circuit, but the idea is the same: a signal is either clearly low or clearly high, never halfway, at least in theory. Switches, push-buttons, sensors and the output pins of a microcontroller can all produce such signals, and a light-emitting diode (LED), a buzzer, a relay or another gate's input can consume them. A truth table is simply a list of every possible combination of inputs and the output the gate produces for each one. With two inputs there are four combinations; with three inputs there are eight, and so on. Truth tables are the most reliable way to understand a gate, because they leave no room for vague descriptions: they state the rule completely.

Binary logic and Boolean expressions

Digital logic is described with Boolean algebra, named after mathematician George Boole. In Boolean algebra, variables hold only the values 0 and 1, and three basic operations combine them. AND is written with a dot or by writing the variables together, as in A · B. OR is written with a plus sign, as in A + B, which does not mean ordinary addition. NOT is written with a bar over the variable, or with a prime mark, as in Ā or A′. Every gate in this guide corresponds to one of these operations or to a combination of them, and writing the Boolean expression next to the gate symbol is a good habit: the expression tells you the rule in one line, and the truth table proves it.

Two conventions are worth learning early. First, in Boolean algebra, 1 + 1 = 1, not 2, because OR means "at least one is true". Second, the order in which you read a truth table matters: inputs are usually listed in counting order, 00, 01, 10, 11 for two inputs, so that no combination is missed. Once you can read a truth table and write its Boolean expression, you can understand any gate, and you can design simple combinations of your own without memorising anything else.

The AND gate: output 1 only when all inputs are 1

The AND gate gives an output of 1 only when every input is 1. If any input is 0, the output is 0. Its Boolean expression for two inputs A and B is Y = A · B. The standard symbol is a flat-backed D shape: inputs enter on the flat left side and the output leaves from the curved right side. A useful everyday picture is two switches in series controlling one lamp: the lamp lights only when both switches are closed, because current must pass through both. The AND gate is the gate of conditions that must all be true at once, such as a machine that may start only when the guard is closed and the start button is pressed and the emergency stop is healthy.

ABY = A · B
000
010
100
111

The OR gate: output 1 when at least one input is 1

The OR gate gives an output of 1 when at least one input is 1, and 0 only when every input is 0. Its Boolean expression is Y = A + B. Its symbol is a pointed shape with a curved input side: the inputs enter on the left through the curved back, and the output leaves from the point on the right. The everyday picture is two switches in parallel controlling one lamp: closing either switch lights the lamp, and closing both lights it as well. OR is the gate of alternatives, such as an alarm that must sound when any one of several sensors trips, or a lamp that can be switched on from either end of a corridor.

ABY = A + B
000
011
101
111

The NOT gate: the inverter

The NOT gate, also called an inverter, has a single input and a single output, and it always gives the opposite of its input: 1 in gives 0 out, and 0 in gives 1 out. Its Boolean expression is Y = Ā. Its symbol is a triangle with a small circle, called a bubble, at the output tip; that bubble means inversion, and you will see it again on NAND, NOR and XNOR symbols. NOT is the simplest gate and one of the most useful, because so many real signals are active-low, meaning that a device is switched on or selected by a low signal rather than a high one. An inverter converts between active-high and active-low signals, and a pair of inverters in series restores the original signal while strengthening it to drive a longer wire or a heavier load.

AY = Ā
01
10

The NAND gate: AND followed by NOT

The NAND gate is an AND gate followed by an inverter, and its name is short for NOT-AND. Its Boolean expression is Y = (A · B) with a bar over the whole expression. Its symbol is the AND symbol with a small inversion bubble at the output. NAND gives 0 only when all inputs are 1; in every other case it gives 1. Notice that this is the exact opposite of AND, row for row. NAND is one of the two universal gates, a title explained later in this guide, and it is the gate most digital chips are actually built from. If you only ever learn one gate deeply, make it NAND, because you can build everything else from it.

ABY = NOT (A · B)
001
011
101
110

The NOR gate: OR followed by NOT

The NOR gate is an OR gate followed by an inverter, short for NOT-OR. Its Boolean expression is Y = (A + B) with a bar over the whole expression. Its symbol is the OR symbol with a small inversion bubble at the output. NOR gives 1 only when every input is 0; if any input is 1, the output is 0. It is the exact opposite of OR, row for row, and it is the other universal gate: like NAND, NOR on its own can build every other gate. NOR is also the natural gate for memory, because two NOR gates cross-coupled, with each output feeding back into the other gate's input, form a basic latch that can hold one bit of information, as explained in the section on combining gates below.

ABY = NOT (A + B)
001
010
100
110

The XOR gate: output 1 when inputs differ

The XOR gate, short for exclusive OR, gives 1 when its two inputs are different and 0 when they are the same. Its Boolean expression is Y = A ⊕ B, where the circled plus is the XOR symbol. Its symbol looks like the OR symbol with an extra curved line on the input side. XOR is the gate of difference: it answers the question "are these two signals not the same?" That question turns out to be extremely useful. In addition, XOR is the sum output of a half adder. In data transmission, XOR is used to generate and check parity bits that detect single-bit errors. In controlled inversion, one input acts as a control signal: when the control is 0, the other input passes through unchanged, and when the control is 1, the other input is inverted, which is exactly how a circuit can choose whether to invert a signal.

ABY = A ⊕ B
000
011
101
110

The XNOR gate: output 1 when inputs are equal

The XNOR gate, short for exclusive NOR, is XOR followed by an inverter, and it gives 1 when its two inputs are the same and 0 when they differ. Its symbol is the XOR symbol with a small inversion bubble at the output. XNOR is therefore an equality detector: it answers the question "are these two signals the same?" That makes it the natural gate for comparators, circuits that compare two binary values bit by bit and report whether they match. If you XNOR each pair of bits in two multi-bit numbers and AND all the results together, the final output is 1 only when the two numbers are identical. XNOR also appears wherever a circuit must confirm agreement between two signals, such as checking that a switch position matches a commanded state before an action is allowed.

ABY = NOT (A ⊕ B)
001
010
100
111

Reading gate symbols at a glance

All seven symbols follow one visual grammar, and learning it makes any schematic readable. The distinctive shape tells you the basic operation: the flat-backed D is AND, the pointed curved shape is OR, and the triangle is NOT. The extra curved line on the input side turns OR into XOR. The small bubble at an output means the result is inverted, which turns AND into NAND, OR into NOR, and XOR into XNOR. Once you know those three rules, you can identify any basic gate symbol on sight, and you can also spot mistakes: a bubble in the wrong place inverts the wrong signal, and that is one of the most common errors in hand-drawn logic diagrams. Draw the bubble deliberately, label every input and output, and check your diagram against its truth table before you build it.

Universal gates: building everything from NAND or NOR

NAND and NOR are called universal gates because either one, used alone, can build every other gate. This is not a curiosity; it is the reason real digital chips are organised the way they are. A manufacturer can perfect one gate design, one transistor arrangement, and then stamp it out in huge numbers, rather than perfecting seven different designs. To see why universality works, take NAND. Tying both inputs of a NAND gate together makes it a NOT gate, because the gate sees the same signal twice: NAND of A with A is NOT (A AND A), and A AND A is simply A, so the result is NOT A. Once you have NOT, you can turn NAND into AND by adding an inverter to its output, and you can build OR from NAND gates by inverting each input first and then NANDing the results, which follows from De Morgan's laws. NOR works the same way in mirror image. You do not need to memorise every construction, but you should remember the principle: a circuit built only from NAND gates, or only from NOR gates, can do anything any combination of gates can do.

De Morgan's laws in plain language

De Morgan's laws are the two rules that let you convert between AND and OR by inverting inputs and outputs. The first says that NOT (A AND B) equals (NOT A) OR (NOT B). The second says that NOT (A OR B) equals (NOT A) AND (NOT B). In practical terms, if you need an AND function but only have NOR gates available, De Morgan's laws show you how to rearrange the circuit to get the same truth table. They also explain why a bubble can sometimes be moved from an output to the inputs of the next gate, with AND and OR swapping places as it moves. Engineers use these laws constantly when simplifying circuits and when converting a design to the gates a particular chip provides.

Combining gates into real circuits

Single gates are only the beginning. Real digital circuits are built by connecting gate outputs to gate inputs, and a handful of combinations appear so often that they have their own names.

The half adder and the full adder

An adder adds binary numbers, and it is built from XOR and AND gates. A half adder adds two single bits: its sum output is A XOR B, and its carry output is A AND B. Work through the four combinations and you will see it matches ordinary addition: 0 + 0 gives sum 0 and carry 0, 0 + 1 and 1 + 0 give sum 1 and carry 0, and 1 + 1 gives sum 0 and carry 1, just as in decimal addition where 1 + 1 gives 0 carry 1 in binary. A full adder adds three bits — two input bits plus a carry-in from a previous stage — using two half adders and an OR gate to combine the carries. Chain full adders together, one per bit, and you can add numbers of any length. This is how the arithmetic inside a processor begins: not with a single clever chip, but with XOR and AND gates repeated in a pattern.

The SR latch: one bit of memory

Connect two NOR gates so that each gate's output feeds back into the other gate's input, and you have an SR latch, the simplest memory circuit. It has two inputs, Set and Reset. A pulse on Set drives the output to 1 and the circuit stays there after the pulse ends, because the feedback holds it. A pulse on Reset drives the output back to 0, and it stays there. The circuit remembers which pulse came last, which is exactly what memory means. Real memory chips are far more elaborate, with clocking, enable signals and many bits, but the idea starts here: feedback turns combinational gates, whose output depends only on their present inputs, into sequential circuits, whose output also depends on their history.

Multiplexers, decoders and comparators

A multiplexer uses AND, OR and NOT gates to select one of several inputs and pass it to a single output, controlled by select signals — like a rotary switch implemented in logic. A decoder does the opposite job: it takes a binary code on its inputs and activates exactly one of many outputs, which is how a binary counter value is turned into the signal that lights one digit on a display or selects one device on a bus. A comparator, as described under XNOR, compares two values bit by bit and reports whether they are equal, or which is larger. These three blocks, built entirely from basic gates, appear inside microcontrollers, display drivers and communication circuits, and recognising them on a schematic is a major step from reading individual gates to reading whole systems.

Logic gates in real circuits

In practice, gates are rarely built from individual switches, although building them that way is an excellent learning exercise. A switch-based AND gate with two switches in series, or a transistor-based NOT gate with a single transistor and a resistor, teaches the logic more vividly than any simulation, and both are safe low-voltage projects for a beginner's bench. For real designs, gates come packaged as integrated circuits: one small chip containing several gates of the same type, such as four two-input NAND gates or six inverters, with power supply pins and one pin per gate input and output. The two long-established logic families are TTL and CMOS, and modern CMOS parts dominate new designs because they draw very little current when idle and work over a wide supply range; whichever family you use, always follow its datasheet for supply voltage, input limits and unused-input handling.

Three practical rules will save you from the most common beginner failures. First, never leave a CMOS gate input floating, unconnected to anything, because a floating input picks up electrical noise and can switch unpredictably or sit halfway between 0 and 1; tie unused inputs to a definite high or low level, or to another used input of the same gate where the datasheet allows it. Second, use pull-up or pull-down resistors on inputs driven by switches or open-collector outputs, so the input has a defined level when the switch is open: a pull-up resistor connects the input to the supply so it reads 1 when nothing pulls it low, and a pull-down resistor connects it to the negative rail so it reads 0 when nothing drives it high. Third, remember that a gate output can only supply or sink a limited current, so driving an LED directly needs a current-limiting resistor, and driving a relay or a motor needs a transistor or driver stage in between, not a bare gate output. The electronics circuits basics guide covers the resistor calculations behind those choices.

Beyond individual chips, gates live inside the programmable devices that dominate modern electronics. A microcontroller such as those used in our ESP32 projects for beginners contains a processor whose arithmetic and control logic is built from gates, and its input and output pins let your programs read switches and sensors and drive displays and actuators through that logic. A data logger is, at heart, gates and memory organised to sample inputs, compare them against thresholds, and store the results, and the displays it writes to are driven by decoders and drivers built from the same gates: our LCD and OLED displays explained guide shows how a binary value becomes a visible character. When you program a microcontroller, you are not escaping logic gates; you are using them at a higher level of abstraction, and knowing what happens underneath makes debugging far easier when a program behaves unexpectedly.

Common mistakes and how to avoid them

The most common mistake is confusing NAND with AND and NOR with OR, forgetting the inversion bubble. Always read the bubble: it flips the entire output, not just one input. The second is confusing XOR with OR, because they agree in three of the four rows and differ only when both inputs are 1: OR gives 1 there, XOR gives 0. If a circuit works for every test except the case where both inputs are high, suspect an XOR-OR mix-up. The third is assuming that gates have unlimited inputs: real gates commonly have two inputs, sometimes three or four, and a function needing more inputs must be built by combining gates, for example by ANDing pairs of inputs and then ANDing the results. The fourth is ignoring timing: real gates take a short time to switch, and in fast circuits the delay through several gates in series can matter, as can glitches, brief wrong outputs that appear when inputs change at slightly different times. For beginner circuits these effects are usually negligible, but knowing they exist explains otherwise mysterious behaviour in faster designs.

A good way to test your understanding is to design a small circuit on paper and verify it with its truth table before building anything. Try these three exercises. First, build an AND gate from NAND gates only, and prove it with a truth table. Second, design a circuit that lights an LED only when two switches are in different positions, and identify which gate it needs. Third, take the half adder described above and extend it to a full adder, then check all eight input combinations. If you can do those three, you understand gates well enough to read real schematics and to start designing your own combinational logic.

Frequently asked questions

What is a logic gate in simple terms?

A logic gate is a small circuit that takes one or more binary inputs, each either 0 or 1, and produces a single binary output according to a fixed rule. The rule is shown in a truth table that lists the output for every possible combination of inputs.

Which logic gates are universal gates?

NAND and NOR are universal gates, because either one on its own can be combined to build every other gate, including AND, OR and NOT. That is why many digital chips are built mainly from NAND or NOR gates.

What is the difference between XOR and XNOR?

XOR gives 1 when its two inputs are different and 0 when they are the same. XNOR is the exact opposite: it gives 1 when its inputs are the same and 0 when they differ, so XNOR is often described as an equality detector.

Next steps: refresh the underlying fundamentals in electronics circuits basics, then put gates to work in ESP32 projects for beginners, see how logic drives visible output in LCD and OLED displays explained, and learn how sampled logic becomes stored measurements in data logger explained.