What is Boolean Logic

Boolean logic is the algebra of true and false. Named after mathematician George Boole, it defines operations — AND, OR, NOT — that take truth values as inputs and produce truth values as outputs. Every if statement, every search query, and every logic gate in a CPU is boolean logic at work.

How it works

There are three fundamental operations:

  • AND — true only when both inputs are true. true AND false = false. In code: a && b.
  • OR — true when at least one input is true. false OR true = true. In code: a || b.
  • NOT — flips the value. NOT true = false. In code: !a.

These combine into more complex expressions. (A AND B) OR (NOT C) evaluates left to right with standard precedence: NOT first, then AND, then OR.

At the hardware level, boolean logic maps directly to bits. True is 1, false is 0. A CPU's arithmetic logic unit (ALU) is built from physical AND, OR, and NOT gates — tiny circuits that implement these operations on electrical signals. Addition in binary is implemented using combinations of AND and XOR (exclusive OR) gates.

Bitwise operations apply boolean logic to every bit in a number simultaneously. 0b1100 AND 0b1010 = 0b1000. This is how CPUs implement bit masks, permission flags, and feature toggles — operations that check or set individual bits within a larger value.

Truth tables enumerate every possible input combination and the resulting output. For AND with two inputs, the table has four rows (2^2 combinations). For three inputs, eight rows. This exhaustive approach is how hardware designers verify circuit correctness.

Why it matters

Boolean logic is where math meets hardware. Every conditional branch in your code compiles down to boolean operations on bits. Every database query with WHERE active = true AND role = 'admin' is boolean logic. Understanding AND, OR, and NOT — and how they compose — is essential for writing correct conditions, debugging unexpected behavior, and understanding how digital circuits compute.

See How Boolean Logic Works for truth tables, De Morgan's laws, and practical applications.