Think of a light switch: it's either on or off, with no in-between setting. Boolean logic, named after 19th-century mathematician George Boole, is built on exactly that same idea applied to statements instead of switches — every statement in this system is either true or false, full stop, and the entire system is a set of rules for combining true/false statements into new true/false statements.

Three operations do almost all the work. AND is true only when both inputs are true — like needing both a key and a code to open a safe, either one missing and it stays locked. OR is true when at least one input is true — like a door that unlocks if either a badge scan or a manager's override succeeds. NOT simply flips a value — true becomes false, and false becomes true, like a switch that inverts whatever comes in.

A truth table just lists every possible combination of inputs and what each operation produces for that combination — a complete, exhaustive answer key rather than something you'd need to reason through case by case:

This is precisely what runs, silently, every time an `if` statement in real code evaluates a condition like `if (isLoggedIn && hasPermission)` — that's AND, checking two true/false values and only proceeding when both are true. `if (isAdmin || isOwner)` is OR. `if (!isExpired)` is NOT. The keywords look like English, but the underlying evaluation is exactly the truth table above, checked mechanically every single time that line of code runs.

Boolean logic scales up cleanly to conditions far more complicated than a single `if` — a search filter with a dozen checkboxes, a spam filter combining dozens of signals, a hardware circuit made of millions of transistors — because all of them, no matter how elaborate, are still built from nothing but AND, OR, and NOT, combined and nested. The complexity comes from how many of these simple operations get chained together, not from any operation being more sophisticated than what's in the table above.

Truth tables for AND, OR, and NOT — every possible input combination, and what each operation outputs.

ABA AND BA OR BNOT A
truetruetruetruefalse
truefalsefalsetruefalse
falsetruefalsetruetrue
falsefalsefalsefalsetrue