This boolean algebra calculator takes two inputs, A and B, each either 0 or 1, and returns the output of one logic gate: AND, OR, XOR, NAND, NOR, XNOR, or NOT A. Pick the gate, set the inputs, and read the result.
Boolean Algebra Calculator
Evaluate a logic gate (AND, OR, XOR, NAND, NOR, XNOR, NOT) for two boolean inputs A and B.
Starting values: the calculator opens with A = 1, B = 0 and the AND gate selected, so the first result you see is 0. Change either input or the gate and the output updates to match.
What this calculator does, and what it does not
The tool evaluates one gate at a time for two single-bit inputs. That is the building block of every digital circuit, and it is the part of boolean algebra you check most often when you are learning or debugging logic. It does not read a typed expression such as (A AND B) OR NOT C, and it does not print a full truth table in one go. To see a whole table, run the four input pairs (00, 01, 10, 11) through the gate you care about and note each output. The table further down shows all of them so you can check your readings.
Only the operators listed in the gate menu are supported. There is no third input, no parentheses and no implication or other operator.
The gates and their formulas
Boolean algebra has two values, 0 and 1. A gate maps its inputs to one of those two values. Here are the rules the calculator applies:
- AND: the output is 1 only when both inputs are 1. Written as A · B, which for single bits is the same as A × B.
- OR: the output is 1 when at least one input is 1. For single bits it equals the larger of A and B.
- XOR (exclusive OR): the output is 1 when exactly one input is 1.
- NAND: the opposite of AND. The output is 0 only when both inputs are 1.
- NOR: the opposite of OR. The output is 1 only when both inputs are 0.
- XNOR: the opposite of XOR. The output is 1 when the inputs are equal.
- NOT A: flips A. 0 becomes 1 and 1 becomes 0. B is ignored for this gate.
A published logic-gate reference describes NAND, NOR and XNOR in the same way, as inversions of AND, OR and XOR, and describes XOR as high only if one input is high. That matches the behaviour above.
Where the variables come from
Where:
- A = the first input bit (0 or 1)
- B = the second input bit (0 or 1)
- Output = the gate result, 0 or 1
The inversion relationships are worth memorising because they let you check any result in two steps:
NAND = NOT (A AND B)
NOR = NOT (A OR B)
XNOR = NOT (A XOR B)
Truth table for every gate
A truth table lists the output of a gate for every possible input combination. With two inputs there are four rows. You can reproduce each row in the calculator by setting A and B to those values and choosing the gate.
| 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 |
NOT A is a one-input gate: A = 0 gives 1, and A = 1 gives 0.
Worked examples
Example 1: the default, AND with A = 1 and B = 0
AND needs both inputs to be 1. Here B is 0, so the output is 0. As arithmetic: 1 × 0 = 0. This is the result the calculator shows when it first loads.
Example 2: OR with A = 1 and B = 0
OR is 1 when at least one input is 1. A is 1, so the output is 1. Using the larger-of-the-two rule, max(1, 0) = 1.
Example 3: XOR with A = 1 and B = 1
XOR is 1 only when exactly one input is 1. Both are 1, so the output is 0. This is the case that separates XOR from OR: OR gives 1 for the same inputs.
Example 4: NAND with A = 1 and B = 1
First find the AND result: 1 AND 1 = 1. NAND inverts it, so the output is 0. NAND is the only two-input gate besides NOR whose output is 0 for the all-ones row and 1 for the other three, so it is easy to spot in a table.
Example 5: XNOR as an equality check
XNOR returns 1 when the two inputs match. With A = 0 and B = 0 the output is 1. With A = 0 and B = 1 it is 0. If you need to know whether two bits are equal, this is the gate to read.
Checking a longer expression by hand
Because the calculator handles one gate at a time, you can still use it to check a longer expression by working from the inside out. Suppose you want (A AND B) OR NOT A with A = 0 and B = 1.
- Evaluate A AND B: 0 AND 1 = 0.
- Evaluate NOT A: NOT 0 = 1.
- Combine the two results with OR: 0 OR 1 = 1.
Each step is one use of the calculator. Write the intermediate values down so you can feed them into the next gate. Repeating this for the other three input pairs builds the full truth table of the expression.
Common mistakes
- Mixing up OR and XOR. They differ in one row only: both inputs 1. OR gives 1 and XOR gives 0.
- Forgetting that NOT A ignores B. If you pick this gate, changing B does nothing.
- Reading NAND as AND with the inputs flipped. It inverts the output, not the inputs.
- Entering values other than 0 and 1. The tool is built for single bits, so keep to those two values.
Where gate logic shows up
The same rules appear in programming conditions, search filters, spreadsheet formulas and digital circuit design. In code, AND and OR are usually written as && and ||, and XOR as ^ on bits. If you work with probabilities of two events, the related ideas are covered in the conditional probability calculator and the compound probability calculator, though those use fractions between 0 and 1 rather than bits.
Frequently asked questions
Can this calculator generate a full truth table?
No. It evaluates one gate for one pair of inputs at a time. To build a truth table, run the four input pairs 00, 01, 10 and 11 through the gate and record each output. The table above lists the results for every supported gate.
Can I type an expression like (A AND B) OR C?
No. The calculator has two inputs and one gate. For a longer expression, work from the innermost gate outward, feeding each result into the next gate, as in the worked example.
What is the difference between OR and XOR?
They agree on every input pair except A = 1 and B = 1. OR returns 1 for that pair and XOR returns 0, because XOR is 1 only when exactly one input is 1.
What does NAND mean?
NAND is AND followed by NOT. It returns 0 only when both inputs are 1, and 1 for every other combination.
