Binary basics

Boolean algebra explained

Two values, three operations and a short list of laws. Learn the rules, simplify expressions step by step and build truth tables.

Written by
Reviewed by
Updated · 7 min read

Boolean algebra is the math for working out what a pile of ANDs and ORs really does, in a logic circuit or an if statement, and for making it shorter. It has two values, 0 for false and 1 for true, and three operations. AND gives 1 only when both inputs are 1, OR gives 1 when at least one input is 1, and NOT flips a value. Any circuit or condition can be written this way, and the laws below let you simplify it before you build or code it.

Key takeaways

Boolean algebra uses only 0 and 1, with three operations: AND, OR and NOT.
NOT is done first, then AND, then OR, the same order as powers, times and plus in school algebra.
In Boolean algebra 1 + 1 = 1, because + means OR, not addition.
Laws such as complement (A + A' = 1) and absorption (A + A·B = A) shrink expressions so circuits need fewer gates.
Any truth table can be turned into an expression by joining the rows that output 1 with OR.
binarytranslator.ai

Boolean expression calculator

Type an expression using A, B and C. Use · or * for AND, + for OR, ' after a letter or ! before it for NOT, and ^ for XOR. The tool builds the truth table, so you can type both sides of a law or a simplification and see whether the output columns match.

The three operations and how they are written

Textbooks, logic courses and programming languages each write the same operations with different symbols. XOR is in the table too, because you'll meet it often, though it can be built from the other three:

OperationAlgebraLogicProgrammingResult is 1 when
ANDA · B or ABA ∧ Ba && bboth are 1
ORA + BA ∨ Ba || bat least one is 1
NOTA' or A with a bar¬A!aA is 0
XORA ⊕ BA ⊻ Ba ^ bthey differ

Order matters the same way it does in school algebra: NOT is done first, then AND, then OR. So A + B · C means A + (B · C), the same way 2 + 3 × 4 means 2 + (3 × 4). Add brackets whenever you want the OR done first.

In Boolean algebra 1 + 1 = 1, which catches people out. The + means OR, and "true or true" is true. That is different from binary addition, where 1 + 1 = 10. The half adder guide shows how circuits do real addition with XOR and AND.

Laws of Boolean algebra

These rules hold for every value of A, B and C, so you can swap one side for the other anywhere in an expression. Most come in pairs. Swap AND with OR and 0 with 1 in one law and you get its partner, which is called the duality principle. Learn one column of the table and you can work out the other.

LawAND formOR form
IdentityA · 1 = AA + 0 = A
Null (annulment)A · 0 = 0A + 1 = 1
IdempotentA · A = AA + A = A
ComplementA · A' = 0A + A' = 1
Double negation(A')' = A
CommutativeA · B = B · AA + B = B + A
Associative(A · B) · C = A · (B · C)(A + B) + C = A + (B + C)
DistributiveA · (B + C) = A·B + A·CA + B·C = (A + B) · (A + C)
AbsorptionA · (A + B) = AA + A·B = A
De Morgan(A · B)' = A' + B'(A + B)' = A' · B'

The second distributive law, A + B·C = (A + B) · (A + C), looks wrong at first because ordinary algebra has no such rule. Here's why it holds. If A is 1, both sides are 1. If A is 0, the left side is B·C and the right side is B · C too. Type each side into the calculator above and all eight rows match. The two De Morgan rules have their own guide with a proof.

Laws of Boolean algebra: identity, null, idempotent, complement, double negation, commutative, distributive, absorption, De Morgan and duality, each in its AND and OR form.

Simplifying Boolean expressions

Simplifying means rewriting an expression with fewer operations, so the circuit needs fewer gates or the condition is easier to read. The usual move is to factor out a shared letter, then look for a term that collapses to 0 or 1. Here are three examples worked all the way through.

Example 1: A·B + A·B'

  1. Factor out A with the distributive law: A · (B + B').
  2. B + B' = 1 by the complement law, so this is A · 1.
  3. A · 1 = A by the identity law, so the whole expression is A. B has no effect on the output.

Example 2: A + A'·B

  1. Use the second distributive law: (A + A') · (A + B).
  2. A + A' = 1, so this is 1 · (A + B).
  3. The result is A + B. The A' adds nothing, because the A'·B term only matters when A is 0, and then A' is 1 anyway.

Example 3: (A + B)·(A + C)

  1. Multiply out: A·A + A·C + B·A + B·C.
  2. A·A = A by the idempotent law, and B·A = A·B, which gives A + A·C + A·B + B·C.
  3. By absorption, A + A·C = A and A + A·B = A, leaving A + B·C.
Simplifying the Boolean expression A AND B OR A AND NOT B: factor out A, use B OR NOT B equals 1, then A AND 1 equals A.

Check every answer the same way: type the original and the result into the calculator and compare the output columns. For example 2, A + A'·B and A + B both give 0, 1, 1, 1. If even one row differs, a step went wrong.

From a truth table to an expression

You can also go the other way. Here is the truth table for A·B + C, the default in the calculator:

ABCA·B + C
0000
0011
0100
0111
1000
1011
1101
1111

To turn any truth table into an expression, take each row where the output is 1. Write that row as an AND of the inputs, with a NOT on each input that is 0, so the term is 1 for that row and no other. Then join the terms with OR. This is called the sum of products. For XOR, the 1 rows are A = 0, B = 1 and A = 1, B = 0, so XOR = A'·B + A·B'. Building from the 0 rows instead gives the product of sums.

For expressions with three or four inputs, engineers often use a Karnaugh map, a grid laid out so neighboring cells differ in one input. Neighboring 1s can be grouped, and each group becomes one shorter term. You get the same answer as the algebra above with fewer chances to slip.

Who invented Boolean algebra

George Boole, an English mathematician, described it in his 1854 book The Laws of Thought, as a way to write logical arguments as equations. It stayed mostly a topic for logicians until 1937, when Claude Shannon showed in a master's thesis he wrote at MIT that year that relay and switch circuits follow the same rules. Digital circuit design has been built on it ever since.

Where Boolean algebra is used

  • In chips, every logic gate is one Boolean operation, and design tools simplify expressions to save gates.
  • In code, a condition such as if (loggedIn && !banned) is a Boolean expression, and the same laws let you rewrite it.
  • Search engines and library databases accept AND, OR and NOT between terms, which is where the phrase "Boolean search" comes from.
  • Bit masks use bitwise AND, OR and XOR, which apply the same rules to every bit of a number at once. The XOR calculator runs them on whole numbers.

Questions people ask

What are the basic laws of Boolean algebra?

Identity, null, idempotent, complement, double negation, commutative, associative, distributive, absorption and De Morgan's laws. The table above lists the AND and OR form of each.

Why is 1 + 1 = 1 in Boolean algebra?

The plus sign means OR, not addition. "True OR true" is true, so the result is 1. Binary addition, where 1 + 1 = 10, is a different operation.

How is Boolean algebra different from normal algebra?

Variables can only be 0 or 1, and some rules change. A + A = A instead of 2A, A · A = A instead of A squared, and A + B·C = (A + B)·(A + C), which is false for ordinary numbers.

How do you simplify a Boolean expression?

Apply the laws one step at a time, usually factoring with the distributive law, then removing terms with the complement, identity and absorption laws. Check the result with a truth table.

What is a Boolean expression?

Any combination of variables and the operations AND, OR and NOT, such as A·B + C'. For each set of input values it gives a single output, 0 or 1.

What is the duality principle?

Every law stays true if you swap AND with OR and 0 with 1. A + 0 = A becomes A · 1 = A, for example.

About the authors

Written byZachary PainterTechnical writer at GitLab

Zachary Painter is a technical writer at GitLab, where he writes developer documentation and UI text. He has written API documentation for REST and GraphQL APIs and reference docs for Kubernetes, Docker and command-line tools, earlier as a technical writer at Pomerium and a senior technical content writer at Stream. He holds a BA in English and German studies from the University of North Carolina at Greensboro. On binarytranslator.ai he writes guides and the how-to sections on tool pages.

All guides by ZacharyLinkedIn

Reviewed byJack GoldsmithSoftware engineer and computer science instructor

Jack Goldsmith is a software engineer and data analyst in New York with a background in teaching. He taught computer science one-on-one at Arts and Athletics, where he worked through students' code with them, and taught Regents Algebra as a lead math teacher at Success Academy. He is an IT and data analysis fellow at the NYC Department of Health and Mental Hygiene and holds a BA in computer science from Queens College. On binarytranslator.ai he checks that worked examples and step-by-step explanations are correct and easy to follow.

ProfileLinkedInHow we review

Keep reading

All posts
In an 8-bit signed integer, 127 + 1 equals -128.Binary basics

MSB and LSB: most and least significant bits, signed integers and overflow

The MSB is the leftmost, highest-value bit and the LSB the rightmost. See what each tells you, how signed integers use the MSB as a sign bit, and how integer overflow wraps values around.9 min read
In floating point, 0.1 + 0.2 equals 0.30000000000000004.Binary basics

Floating point numbers explained: why 0.1 + 0.2 is not 0.3

A floating point number is scientific notation in binary. See why 0.1 + 0.2 is 0.30000000000000004, how precise floats are, float vs double, and how to compare floats and handle money.9 min read
The hexadecimal number 2F3 equals 755 in decimal.Binary basics

What is hexadecimal? The base 16 number system explained

Hexadecimal is base 16, with digits 0 to 9 and A to F. See how place values work, why programmers use hex for bytes, the values worth knowing and how octal compares.7 min read
Scroll to Top