🏆 US-Registered Digital Marketing Agency
Advertisement
Advertisement
DEVELOPER

Logic Gate Calculator — AND, OR, XOR, NAND, NOR

Set the inputs to any logic gate and see the output, the gate's complete truth table, and how the same function is built from NAND gates alone.

NOT and BUFFER take a single input; the others take two or more.
Real gates come in fixed input counts, but multi-input AND, OR, NAND and NOR are standard parts. Up to six here, giving a 64-row table.
One character per input, using 1 and 0 (T and F also work). The leftmost character is input A. Everything is evaluated in your browser.
Filtering to the output-1 rows gives you the minterms directly, which is where a sum-of-products expression comes from.
Output for these inputs
0
 
Gate
0
Rows in truth table
0
Rows where output is 1
Boolean expression
Truth table:
Built from NAND gates:
Advertisement

The logic gate calculator above evaluates any of the eight standard gates for the input values you set, prints the gate's complete truth table for that number of inputs, and shows the equivalent circuit made from NAND gates alone. It runs as local JavaScript in your browser, so nothing you enter is transmitted anywhere.

Arb Digital publishes this alongside its other free developer tools because gate behaviour is easy to half-remember and expensive to get wrong. The difference between XOR and OR shows up only when both inputs are 1, and the difference between NAND and NOR is invisible on half the rows of a two-input table. A table settles it in a second.

What This Logic Gate Calculator Does

Each gate is a Boolean function: it takes one or more inputs that are each 0 or 1 and produces a single output. AND outputs 1 only when every input is 1. OR outputs 1 when at least one input is 1. NOT inverts its single input. NAND and NOR are AND and OR followed by an inversion. XOR outputs 1 when an odd number of inputs are 1, which for two inputs means exactly one of them. XNOR is its complement, outputting 1 when the inputs agree. BUFFER passes its input through unchanged, which sounds pointless until you need to restore a signal or add a deliberate delay.

The tool extends AND, OR, NAND, NOR, XOR and XNOR to as many as six inputs, generates the full 2n-row table, and lets you filter to just the rows where the output is 1 — the minterms — or just the rows where it is 0.

Boundary worth stating: this page is about individual gates. If you want to type an arbitrary Boolean expression such as (A AND B) OR NOT C and get its table, that is the job of the truth table generator. This one answers “what does this gate do”; that one answers “what does this expression do”.

How to Use It

  1. Choose a gate. The expression, symbol convention and NAND equivalent all update with it.
  2. Set the number of inputs. Two is the common case; raising it shows how multi-input AND, OR and XOR behave.
  3. Type the input values. One character per input, so 101 means A is 1, B is 0 and C is 1.
  4. Read the highlighted row. The truth table marks the row that matches your inputs, so you can see it in the context of every other combination.
  5. Filter to output-1 rows when deriving an expression. Each of those rows is a minterm, and their sum is the canonical sum-of-products form.

The Gates and Their Definitions

Writing A and B for the inputs, the standard notation is a dot or juxtaposition for AND, a plus for OR, an overbar or apostrophe for NOT, and a circled plus for XOR. The two-input tables are:

AND: 0·0=0, 0·1=0, 1·0=0, 1·1=1. Output is 1 only when both inputs are 1.
OR: 0+0=0, 0+1=1, 1+0=1, 1+1=1. Output is 0 only when both inputs are 0.
XOR: 0⊕0=0, 0⊕1=1, 1⊕0=1, 1⊕1=0. Output is 1 when the inputs differ.
NAND, NOR and XNOR are the complements of the three above, row for row.

Two identities are worth memorising, because they are the ones people get wrong under pressure. De Morgan's laws say that NOT(A AND B) equals NOT A OR NOT B, and NOT(A OR B) equals NOT A AND NOT B. Inverting a compound expression flips every operator as well as every term, and forgetting the operator flip is the classic bug in a negated condition. The symbols used to draw these gates on a schematic are standardised in IEEE Std 91/91a, IEEE Standard Graphic Symbols for Logic Functions, which defines both the distinctive shapes most engineers recognise and the rectangular symbols with qualifying notation.

Advertisement

Why NAND and NOR Are Called Universal Gates

Any Boolean function whatsoever can be built from NAND gates alone, and equally from NOR gates alone. That is not a curiosity; it is the reason NAND is the workhorse of real silicon. In CMOS, a NAND gate needs four transistors and is faster than the equivalent AND gate, which is a NAND followed by an inverter and therefore needs six. Designing in terms of NAND saves area and delay simultaneously.

The constructions are short. A NOT gate is a NAND with both inputs tied together, since NOT(A AND A) is NOT A. An AND gate is a NAND followed by that inverter. An OR gate is two inverters into a NAND, which is De Morgan's law read backwards: NOT A NAND NOT B equals A OR B. XOR takes four NAND gates in the classic arrangement. The tool shows the relevant construction for whichever gate you have selected, which is a useful sanity check when you are minimising a design by hand. MIT OpenCourseWare's 6.004 Computation Structures covers combinational logic and CMOS gate construction in its published lecture materials if you want the full derivation.

Reading a Truth Table Properly

A table with n inputs has 2n rows, because each input doubles the number of combinations. Two inputs give four rows, three give eight, six give sixty-four. That exponential growth is why exhaustive testing works beautifully for a single gate and not at all for a circuit with thirty-two inputs, where the table would have more rows than there are grains of sand on Earth.

The conventional ordering counts up in binary with the leftmost input as the most significant bit, so the rows for three inputs run 000, 001, 010, 011, 100, 101, 110, 111. Keeping that order matters when you compare two tables: a table written in a different row order describes the same function but will not line up for a visual diff.

Reading an expression out of a table is mechanical. For each row where the output is 1, write a product term with each input appearing plain if it is 1 in that row and inverted if it is 0. Join those terms with OR. That gives the canonical sum-of-products form, which is correct but rarely minimal — Karnaugh maps and the Quine–McCluskey algorithm exist to reduce it. Filtering this tool to output-1 rows gives you exactly the list of minterms to start from.

Where Gate Logic Meets Everyday Code

The same functions appear in software as bitwise operators, and one distinction causes real bugs: bitwise operators apply the gate to every bit position independently, while logical operators reduce their operands to a single true or false and often short-circuit. In most C-family languages, 6 & 3 is 2 because the operation runs bit by bit, whereas 6 && 3 is true. Using the wrong one usually still compiles and sometimes still passes tests.

XOR earns a special mention because of its properties: it is its own inverse, so applying the same value twice restores the original, and it produces 0 exactly when its inputs are equal. That makes it the basis of parity bits, simple checksums, difference detection, and the stream-cipher combining step. It is also why swapping two variables with three XOR operations works, though modern compilers make that trick pointless. For bit-level work on whole numbers, the bitwise calculator applies these operations across full values, the binary arithmetic calculator handles addition and subtraction in binary, and the two's complement converter explains how negative numbers are encoded before any of it happens.

Need a site whose logic actually holds up?

Arb Digital builds websites and web applications with conditions that behave the way the specification says they should, on every path.

See Web Design Services Talk to Arb Digital

Common Mistakes to Avoid

  • Confusing OR with XOR. They differ on exactly one row of a two-input table, the one where both inputs are 1, and that row is often the interesting case.
  • Applying De Morgan's law without flipping the operator. NOT(A AND B) is NOT A OR NOT B. Changing only the terms and leaving AND in place inverts the meaning of the condition.
  • Mixing bitwise and logical operators. A single ampersand works per bit; a double one reduces to true or false and short-circuits. Both compile, and only one is correct.
  • Assuming multi-input XOR means “exactly one”. With more than two inputs it means an odd number of them are 1, which is not the same condition.
  • Expecting to test a large circuit exhaustively. Rows double with every input, so a table is a design aid for small blocks, not a verification strategy for a whole design.

Related Free Tools From Arb Digital

For arbitrary Boolean expressions rather than single gates, use the truth table generator. The bitwise calculator applies AND, OR, XOR and shifts to whole numbers, the binary arithmetic calculator covers binary addition and subtraction, and the two's complement converter handles signed encoding. The number base converter moves integers between bases, and the floating point converter does the same for real numbers under IEEE 754. Everything else is in the free online tools hub.

Frequently Asked Questions

What is the difference between OR and XOR?

OR outputs 1 when at least one input is 1, including when both are. XOR outputs 1 only when the inputs differ, so with both inputs at 1 it outputs 0. They agree on three of the four rows of a two-input table.

Why are NAND and NOR called universal gates?

Because every Boolean function can be built from NAND alone, or from NOR alone. A NAND with its inputs tied together is an inverter, a NAND plus an inverter is an AND, and inverting both inputs of a NAND produces OR.

How many rows does a truth table have?

Two raised to the number of inputs. Two inputs give four rows, three give eight, and six give sixty-four. The count doubles with each additional input, which is why exhaustive tables suit small blocks only.

What do De Morgan's laws say?

That NOT(A AND B) equals NOT A OR NOT B, and NOT(A OR B) equals NOT A AND NOT B. Negating a compound expression flips the operator as well as the terms, which is the step most often forgotten.

What does XOR do with more than two inputs?

It outputs 1 when an odd number of inputs are 1. That is why it is used for parity generation and checking, and why it does not mean “exactly one input is high” once you go beyond two inputs.

How do I get a Boolean expression from a truth table?

Take every row where the output is 1 and write a product term in which each input appears plain if it is 1 in that row and inverted if it is 0, then join the terms with OR. That canonical sum-of-products form is correct but usually not minimal.

What is the point of a buffer gate?

It outputs its input unchanged, which is used to restore signal strength when driving many loads, to add a controlled delay, or as the basis of a tri-state buffer that can disconnect its output from a shared bus.

Is anything I enter here sent anywhere?

No. The evaluation runs in your browser as local JavaScript. The page makes no network request, stores nothing and logs nothing.

Advertisement
Advertisement

Take it further