Skip to content

What is a logic gate? The seven basic gates with symbols, truth tables and examples

A logic gate is a small circuit, or its symbol on a diagram, that takes one or more inputs, each 0 or 1, and gives one output by a fixed rule: its truth table. The seven basic gates are NOT, AND, OR, NAND, NOR, XOR and XNOR.

This guide gives each gate's symbol in both drawing standards, its Boolean expression, its truth table and a place where it is used. It then shows how a gate works inside a chip, why NAND and NOR can build every other gate, and how to turn a rule written in words into a circuit. The truth tables on this page are computed by the Tangibool engine, and each claim that two circuits do the same thing links to a free checker that shows it.

The seven basic logic gates at a glance

Every gate below is shown with two inputs, A and B, except NOT, which has one. 1 means true, a high voltage in a circuit, and 0 means false, a low voltage.

GateOutput is 1 whenBoolean expressionIn code (true/false values)
NOT, the inverterthe input is 0A′ or ¬A!a
ANDboth inputs are 1A · B or A ∧ Ba && b
ORat least one input is 1A + B or A ∨ Ba || b
NANDat least one input is 0(A · B)′!(a && b)
NORboth inputs are 0(A + B)′!(a || b)
XORthe inputs differA ⊕ Ba != b
XNORthe inputs are the same(A ⊕ B)′a == b

The names say how the last four are built. NAND is “not AND”, NOR is “not OR”, XOR is “exclusive OR” and XNOR is “exclusive NOR”. NAND, NOR and XNOR are AND, OR and XOR followed by a NOT, and their symbols are the same shapes with a small circle, the sign for NOT, on the output.

All seven gates in one truth table

A truth table lists every combination of inputs with the output for each. Two inputs give four rows. Here are all seven gates on the same four rows. T stands for 1 and F for 0, and row 0 has both inputs at 0, as in Tangibool's tools.

Truth table: NOT A, AND, OR, NAND, NOR, XOR, XNOR
#ABNOT AANDORNANDNORXORXNOR
0FALSEFALSETRUEFALSEFALSETRUETRUEFALSETRUE
1FALSETRUETRUEFALSETRUETRUEFALSETRUEFALSE
2TRUEFALSEFALSEFALSETRUETRUEFALSETRUEFALSE
3TRUETRUEFALSETRUETRUEFALSEFALSEFALSETRUE

Computed by the Tangibool engine

Three patterns are worth seeing:

  • AND is 1 on a single row, and OR is 0 on a single row. AND needs every input, OR needs any input.
  • A gate with a circle is the gate without it, inverted: compare AND with NAND, OR with NOR, and XOR with XNOR. Each pair of columns is opposite on every row.
  • XOR is 1 exactly where the inputs differ, rows 1 and 2, and XNOR exactly where they agree, rows 0 and 3.

The NOT column depends only on A. It is 1 on rows 0 and 1, where A is 0.

How a logic gate works

Inside a chip, a bit is a voltage on a wire. A voltage near 0 volts stands for 0, and one near the supply voltage stands for 1. A gate is a group of transistors that drives its output wire to the right voltage for the voltages on its input wires.

The idea is easiest to see with switches. Put two switches in series between a battery and a lamp, and the lamp lights only when both are closed: that is AND. Put them side by side, in parallel, and either switch lights the lamp: that is OR. A transistor is a switch that a voltage opens and closes, so the output of one gate can drive the inputs of the next, and gates can be chained by the million.

In CMOS, the technology of almost every chip made today, the simplest gates are the inverting ones. An inverter (NOT) takes two transistors. A two-input NAND takes four: two in series that pull the output down to 0 only when both inputs are 1, and two in parallel that pull it up to 1 whenever either input is 0. An AND gate is a NAND followed by an inverter, six transistors in all. That is why chip designers think in NAND and NOR, and why those two gates have their own section below.

Three things a truth table does not show:

  • Memory. A gate's output depends only on its inputs at that moment. Circuits made of gates without loops are called combinational logic. Memory comes from feeding a gate's output back to an input, as in a latch.
  • Delay. A real gate takes time to respond, from picoseconds inside a processor to a few nanoseconds in a separate chip. The truth table gives the output once it has settled. Tangibool's tools compute what a gate outputs, not when.
  • Fan-out. One output can feed several inputs, up to a limit set by the electronics. A diagram shows it as one wire branching, and the word for it is fan-out.

Gates exist in software too. The operators &&, || and ! in C, Java and JavaScript, and and, or and not in Python, are AND, OR and NOT on true and false. The bitwise operators &, |, ^ and ~ apply AND, OR, XOR and NOT to each bit of a number, 32 or 64 gates at once.

The seven gates one by one

NOT gate (inverter)

A NOT gate has one input and outputs the opposite value: 0 becomes 1, and 1 becomes 0. It is written ¬A, A′ (“A prime”), NOT A, or with a bar over the letter. Its symbol is a triangle pointing the way the signal travels, with a small circle at its tip. The circle, called a bubble, is the part that means “not”, and it appears on every inverting gate.

Where it is used: many buttons and sensors are wired so that “pressed” or “alarm” pulls the line down to 0, which is called active-low. A NOT gate turns such a signal into one that is 1 when the button is pressed.

The truth table generator shows its two rows and draws the symbol, and the NOT operator page covers the notations.

AND gate

An AND gate outputs 1 only when every input is 1. It is written A · B or AB in electronics, A ∧ B in logic, and A AND B in words. The symbol has a flat back and a rounded front, like a capital D.

Where it is used: a machine that may start only when the start button is pressed and the guard is closed. The machine interlock example adds the emergency stop to that rule. With three or more inputs, AND is still 1 on a single row, the one where every input is 1.

The truth table generator draws the gate with its table, and the AND operator page has the tables for three and four inputs.

OR gate

An OR gate outputs 1 when at least one input is 1, including when both are. It is written A + B, A ∨ B or A OR B. The symbol has a curved back and a pointed front, like a shield.

Where it is used: a burglar alarm that sounds when the door, a window or the motion sensor trips, as in the alarm rule example. The gate's OR is inclusive, “A or B or both”. The everyday “or” that rules out “both” is XOR, and the page on inclusive vs exclusive or shows the row where they part.

The truth table generator draws the gate, and the OR operator page has the larger tables.

NAND gate

A NAND gate is an AND followed by a NOT: it outputs 0 only when every input is 1. Read it as “not both”. By De Morgan's law, NAND(A, B) is the same as NOT A OR NOT B, “at least one input is 0”, and the equivalence checker confirms it on all four rows. The symbol is the AND shape with a bubble on the output.

Where it is used: two NAND gates, each feeding its output back into the other's input, store one bit. That loop, a latch, is where computer memory starts. NAND flash memory, in USB sticks and solid-state drives, takes its name from the gate, because its memory cells are connected in series like the transistors that pull a NAND gate's output down.

The truth table generator draws the gate, and the NAND operator page has the tables for three and four inputs.

NOR gate

A NOR gate is an OR followed by a NOT: it outputs 1 only when every input is 0. Read it as “neither … nor”. By De Morgan's law, NOR(A, B) is the same as NOT A AND NOT B. The symbol is the OR shape with a bubble.

Where it is used: like NAND, NOR can build every other gate, and some machines were built from nothing else. The Apollo Guidance Computer, which flew the Moon landings, was built almost entirely from one kind of chip: two three-input NOR gates in one package.

The truth table generator draws the gate, the NOR operator page has the larger tables, and the page on “neither … nor” covers the English.

XOR gate

An XOR gate, exclusive OR, outputs 1 when its two inputs differ. It is written A ⊕ B or A XOR B. It is OR without the “both” row, (A OR B) AND NOT (A AND B). The symbol is the OR shape with a second curved line behind the inputs.

Where it is used: XOR adds two bits and drops the carry, so it gives the sum of a half adder, whose carry is an AND. It also flips bits on command: A XOR 1 is NOT A, and A XOR 0 is A, which is how parity bits and simple checksums are computed. A light controlled by two switches at either end of a staircase is an XOR: flipping either switch changes the light.

The truth table generator draws the gate, and the XOR operator page has the tables for three and four inputs.

XNOR gate

An XNOR gate outputs 1 when its two inputs are the same, both 0 or both 1. It is XOR followed by NOT, and it is the same function as the biconditional A ↔ B of logic. Tangibool's tools write it XNOR(A, B), and the equivalence checker shows it equals (A AND B) OR (NOT A AND NOT B), “both or neither”. The symbol is the XOR shape with a bubble.

Where it is used: one XNOR per bit tests whether two numbers are equal. AND the results together and the output is 1 only when every bit matches, as in the two-bit equality example.

The truth table generator draws the gate, and the XNOR operator page has the larger tables.

Logic gate symbols: ANSI and IEC

Two drawing standards are in use. The distinctive shapes, from the American standard ANSI/IEEE Std 91, are the ones in most textbooks. The rectangular symbols, from IEC 60617, draw every gate as the same box and mark its function inside; they are common in European and industrial drawings.

GateDistinctive shape (ANSI)Rectangular symbol (IEC)
NOTTriangle with a bubble at the tipBox marked 1, with a bubble at the output
ANDFlat back, rounded front (a D)Box marked &
ORCurved back, pointed frontBox marked ≥1
NANDAND shape with a bubble at the outputBox marked &, with a bubble at the output
NOROR shape with a bubble at the outputBox marked ≥1, with a bubble at the output
XOROR shape with an extra curved line at the inputsBox marked =1
XNORXOR shape with a bubble at the outputBox marked =1, with a bubble at the output
BufferTriangle without a bubbleBox marked 1

The IEC marks say what the gate counts: & means every input is 1, ≥1 means at least one is, and =1 means exactly one is. In both standards a bubble on an input or an output means NOT at that point, so a gate drawn with bubbles on its inputs inverts them before it acts. A buffer passes its input through unchanged. It strengthens a signal rather than computing anything, which is why it is not one of the seven.

On this site the truth table generator and the logic circuit generator draw the distinctive shapes, with the gate's name written inside each one, so a diagram can be read without knowing the shapes.

Gates with more than two inputs

AND, OR, NAND and NOR extend to any number of inputs, and chips with three, four and eight inputs are common. A three-input AND is 1 on one row of eight, and a three-input NAND is 0 on that one row. NOT (A AND B AND C) is the same as NOT A OR NOT B OR NOT C, De Morgan's law with three terms. In Tangibool's notation NAND, NOR and XNOR take exactly two inputs, so a three-input NAND is written NOT (A AND B AND C).

XOR is where more inputs surprise people. A chain of two-input XOR gates, A XOR B XOR C, outputs 1 when an odd number of inputs are 1, so it is 1 when all three are. That is a parity check, not “exactly one”. The equivalence checker compares it with the formula for “exactly one of three” and gives the counterexample A = B = C = T. The IEC symbols keep the two apart: with more than two inputs, =1 means exactly one, and an odd-parity gate is marked 2k+1. The page on three-input XOR has both tables.

NAND and NOR: the universal gates

A gate is universal when every other gate can be built from copies of it alone. NAND and NOR are both universal: each can make NOT, AND and OR, and those three can make any circuit. Here are the constructions, each linked to the equivalence checker, which compares it with the gate it builds on every row:

Read the NAND column from the top. Feeding the same signal to both inputs of a NAND gives NOT. AND is a NAND followed by that NOT. OR is a NAND of the two inverted inputs, because NOT (NOT A AND NOT B) is A OR B by De Morgan's law. The NOR column is the same with AND and OR exchanged. The laws section proves each construction on its own page, starting with NOT from NAND.

AND and OR alone are not universal, because they cannot invert. Changing an input from 0 to 1 can never change the output of a circuit of AND and OR gates from 1 to 0, and that is exactly what NOT does. XOR is not universal either: with a constant 1 it makes NOT, but no circuit of XOR gates makes AND. The universal gate entry in the glossary has more.

Built by hand, universal circuits can be shorter than the table suggests. The classic XOR from four NAND gates, NAND(NAND(A, NAND(A, B)), NAND(B, NAND(A, B))), is equivalent to A XOR B and uses fewer gates than the three constructions above put together; the worked example goes through it. The NAND and NOR converter rewrites any expression with one gate type and checks the result against the original. Its gate count is for the expression as written, where a repeated part appears twice; in a circuit that part is built once and wired to both places. The NAND vs NOR page sets the two families side by side.

From a rule to a circuit: a worked example

A rule written in words becomes a circuit in four steps. Take a garage door:

The door motor runs when the wall button or the remote is pressed, and nothing is blocking the safety beam.

1. Name the inputs. button is 1 when the wall button is pressed, remote is 1 when the remote is pressed, and blocked is 1 when something breaks the beam.

2. Write the expression. The “or” joins the two ways of asking, and “nothing is blocking” is NOT blocked: motor = (button OR remote) AND NOT blocked.

3. Make the truth table. Three inputs give 2³ = 8 rows. The first two columns are the outputs of the OR gate and the NOT gate, the signals inside the circuit:

Truth table: button OR remote, NOT blocked, motor
#buttonremoteblockedbutton OR remoteNOT blockedmotor
0FALSEFALSEFALSEFALSETRUEFALSE
1FALSEFALSETRUEFALSEFALSEFALSE
2FALSETRUEFALSETRUETRUETRUE
3FALSETRUETRUETRUEFALSEFALSE
4TRUEFALSEFALSETRUETRUETRUE
5TRUEFALSETRUETRUEFALSEFALSE
6TRUETRUEFALSETRUETRUETRUE
7TRUETRUETRUETRUEFALSEFALSE

Computed by the Tangibool engine

The motor runs on rows 2, 4 and 6: at least one button pressed and the beam clear. On row 7 both buttons are pressed but the beam is blocked, so the AND gate keeps the motor off.

4. Draw the gates. One OR gate takes button and remote, one NOT gate takes blocked, and one AND gate takes both results. The truth table generator computes the same table and draws the three gates.

The same door can be built from one type of gate. With NOR gates, two are enough: NOR(NOR(button, remote), blocked) is equivalent to the rule. The inner gate is 1 when neither button is pressed, and the outer gate is 1 only when that is 0 and blocked is 0. The NAND converter builds the rule from its parts and gives NAND(x, x), where x is NAND(NAND(NAND(button, button), NAND(remote, remote)), NAND(blocked, blocked)). The equivalence checker confirms it, and with x built once it is six gates. Arranged by hand, four NAND gates do the job: NAND(NAND(button, NAND(blocked, blocked)), NAND(remote, NAND(blocked, blocked))), which reads “the button and a clear beam, or the remote and a clear beam”. A converter's construction is a correct circuit, not necessarily the smallest one, which is why the tool checks equivalence and leaves the gate count to you.

Where logic gates are used

  • Arithmetic. Adding two bits gives a sum, A XOR B, and a carry, A AND B: the half adder. Two half adders and an OR gate make a full adder, which also adds the carry from the column before. The plainest 64-bit adder is a chain of 64 full adders; processors use faster arrangements of the same gates.
  • Choosing. A 2-to-1 multiplexer passes one of two inputs to its output, depending on a select line S: (S AND B) OR (NOT S AND A). Processors route data with multiplexers.
  • Comparing. One XNOR per bit tests equality, and the one-bit comparator also says which bit is greater.
  • Remembering. Two cross-coupled NOR or NAND gates form a latch that holds one bit. Flip-flops, registers and static RAM are built on the same loop.
  • Safety and control. Interlocks, alarms and traffic-light checks are AND, OR and NOT rules, often run on a programmable logic controller rather than built from separate chips.
  • Software and search. Every if condition with &&, || or ! is a small gate circuit, and so is a search for “logic AND gates NOT electronics”. Feature flags and eligibility rules are gate circuits that run as code.

Common mistakes

  1. Reading NAND as “not A and not B”. That is NOR. NAND means “not both”, and it is 1 on three rows. The equivalence checker shows that NAND(A, B) and NOT A AND NOT B differ, with the counterexample A = F, B = T: one input is 0, so NAND gives 1, but NOT A AND NOT B gives 0.
  2. Using a chain of XOR for “exactly one”. With three inputs it is also 1 when all three are 1, as shown above.
  3. Missing a bubble. A small circle anywhere on a gate is a NOT. An AND gate with bubbles on both inputs computes NOT A AND NOT B, which is NOR, not NAND.
  4. Mixing up logical and bitwise operators. In C, Java and JavaScript, && is the AND of two conditions and & is AND applied bit by bit; ! is logical NOT and ~ flips every bit of a number. Tangibool's tools reject a single & and a ~ with a message instead of guessing; see the single ampersand.
  5. Writing AB for A AND B. Electronics books often drop the dot, but in a tool or a program AB is one name. See implicit multiplication.

Try it yourself

  1. Write the circuit as an expression. Name each input, and use AND, OR, NOT and XOR between them. The tools also accept ∧, ∨, ¬ and ⊕, and the algebra forms A·B, A + B and A′. NAND, NOR and XNOR are written as functions of two inputs: NAND(A, B).
  2. Paste it into the truth table generator for the table and the drawing, or into the logic circuit generator for the diagram with a plain-language reading beside it.
  3. To check that two circuits do the same thing, put one in each box of the equivalence checker. If they differ, it shows an input combination where they do.

Frequently asked questions

What is a logic gate in simple terms?

A circuit with one output that is 1 or 0, set by its inputs according to a fixed rule. An AND gate, for example, outputs 1 only when all its inputs are 1.

What are the seven basic logic gates?

NOT, AND, OR, NAND, NOR, XOR and XNOR. AND, OR and NOT are enough to build the other four, and NAND or NOR alone is enough to build all seven.

How does a logic gate work?

Inside a chip, 0 and 1 are a low and a high voltage, and a gate is a few transistors acting as switches that connect its output to the high or the low voltage depending on its inputs. A two-input NAND gate in CMOS uses four transistors.

What do the logic gate symbols mean?

The shape gives the function: a D shape for AND, a shield for OR, a triangle for NOT, and the OR shape with an extra curve for XOR. A small circle on an output or an input means NOT. In the rectangular IEC style the box is marked & for AND, ≥1 for OR, =1 for XOR and 1 for NOT.

Why are NAND and NOR called universal gates?

Because NOT, AND and OR, and so every other circuit, can be built from NAND gates alone or from NOR gates alone. The constructions are in the table above, each with a link to the equivalence checker.

What is the difference between AND and NAND?

Their outputs are opposite on every row. AND is 1 only when all inputs are 1, and NAND is 0 only then. A NAND gate is an AND gate followed by a NOT gate.

What is the difference between OR and XOR?

They differ on one row: when both inputs are 1, OR gives 1 and XOR gives 0. The XOR vs OR comparison shows the two tables side by side.

How many inputs can a logic gate have?

NOT has one. The others can have two or more, and chips commonly offer two, three, four and eight. XOR and XNOR need care with more than two inputs, because a chain of XOR gates computes parity.

Is a logic gate hardware or software?

Both. The word first meant a physical circuit, but the same functions are the logical operators of every programming language, and a logic diagram describes the function whatever builds it.

How many rows does a gate's truth table have?

2 to the power of the number of inputs: 2 rows for NOT, 4 for a two-input gate, 8 for three inputs and 16 for four.

Written by Muaz Notiar. The Tangibool engine (semantics tangibool-semantics/1, engine 1.0.0) computed the 2 truth tables marked “Computed by the Tangibool engine”, and the 25 tool results the guide links to were re-run through the tools' own code in the build of and match what the text says. © 2026 Foreranger LTD.