Boolean Data Type
Truth Tables at a High Level
Read aloud is unavailable in this browser.
The Complete Definition of Boolean Logic
How do you precisely define what AND, OR, and NOT mean? Not through vague English descriptions, but with mathematical rigor that leaves no ambiguity?
The answer is the truth table—a systematic enumeration of every possible input combination and its corresponding output. Truth tables are the formal specification of boolean operations, used identically by logicians, mathematicians, computer scientists, and electrical engineers.
When you truly understand truth tables, you possess the complete knowledge of boolean logic. There are no hidden cases, no edge conditions, no surprises—the truth table shows everything.
By the end of this page, you will understand truth tables as the formal definition of boolean operations, master the fundamental operations (AND, OR, NOT, XOR, NAND, NOR), see how complex expressions decompose into truth tables, and recognize why these concepts matter for both programming and hardware.
What Is a Truth Table?
A truth table is a tabular representation that exhaustively lists every possible combination of inputs to a boolean expression along with the resulting output.
The structure of a truth table:
- Input columns: One column for each boolean variable (A, B, C, ...)
- Output column(s): The result of the boolean expression
- Rows: Every possible combination of input values
For n inputs, there are 2ⁿ rows:
| Inputs | Possible Combinations |
|---|---|
| 1 variable (A) | 2 rows: T, F |
| 2 variables (A, B) | 4 rows: TT, TF, FT, FF |
| 3 variables (A, B, C) | 8 rows |
| 4 variables | 16 rows |
| n variables | 2ⁿ rows |
Why truth tables are complete:
A boolean variable has exactly 2 states. With n independent variables, the total possibility space is 2 × 2 × ... × 2 = 2ⁿ. The truth table covers every point in this space—no combination is missed, no ambiguity remains.
Truth table as contract:
Think of a truth table as a contract that completely specifies the behavior of a boolean operation. If you follow the inputs down to the corresponding row, you will find the exact output—guaranteed, always, universally true.
Truth tables use various notations: T/F, True/False, 1/0, High/Low. We'll use T (true) and F (false) for clarity. In digital circuits, 1 and 0 are more common. The concepts are identical regardless of notation.
The NOT Operation (Negation)
The simplest boolean operation is NOT, also called negation or inversion. It takes a single input and produces its opposite.
Symbols:
- Logic: ¬A, NOT A
- Programming: !A, ~A (bitwise)
- Electronics: A with overbar (Ā)
The truth table for NOT:
| A | NOT A |
|---|---|
| T | F |
| F | T |
Understanding NOT:
NOT simply flips the value:
- True becomes false
- False becomes true
Key properties of NOT:
- Involution: NOT(NOT(A)) = A (double negation returns original)
- Complement: A and NOT(A) are always different
- Symmetry: NOT treats true and false symmetrically
Programming examples:
isLoggedIn = true
if (!isLoggedIn) { // NOT isLoggedIn → false
redirectToLogin()
}
doorLocked = false
if (!doorLocked) { // NOT false → true
allowEntry()
}
Common patterns:
!isEmpty→ "has content"!isValid→ "is invalid"!found→ "still searching"
NOT interacts with AND and OR in profound ways captured by De Morgan's laws: NOT(A AND B) = (NOT A) OR (NOT B), and NOT(A OR B) = (NOT A) AND (NOT B). We'll see these in the complex expressions section.
The AND Operation (Conjunction)
AND, also called conjunction, outputs true only when all inputs are true. It represents the logical concept of "both conditions must hold."
Symbols:
- Logic: A ∧ B, A AND B
- Programming: A && B, A & B (bitwise)
- Electronics: A · B
The truth table for AND:
| A | B | A AND B |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | F |
Understanding AND:
- Only the first row produces true (both inputs true)
- Any false input makes the result false
- AND is the most "restrictive" binary operation
Key properties of AND:
- Identity: A AND true = A (true is the identity element)
- Annihilation: A AND false = false (false dominates)
- Idempotence: A AND A = A
- Commutativity: A AND B = B AND A
- Associativity: (A AND B) AND C = A AND (B AND C)
Programming examples:
// Both conditions must be true
if (hasPermission && isAuthenticated) {
grantAccess()
}
// Guard pattern using AND
if (array != null && array.length > 0) {
processFirstElement(array[0])
}
Real-world analogy:
AND is like a series circuit with two switches. Current flows (output = true) only if both switches are closed (both inputs = true). Open either switch, and the circuit breaks.
AND extends naturally to more inputs: A AND B AND C AND D is true only if ALL inputs are true. With n inputs, there's exactly 1 true output (all inputs true) and 2ⁿ-1 false outputs.
The OR Operation (Disjunction)
OR, also called disjunction, outputs true when at least one input is true. It represents the logical concept of "either condition may hold" (inclusive or).
Symbols:
- Logic: A ∨ B, A OR B
- Programming: A || B, A | B (bitwise)
- Electronics: A + B
The truth table for OR:
| A | B | A OR B |
|---|---|---|
| T | T | T |
| T | F | T |
| F | T | T |
| F | F | F |
Understanding OR:
- Only the last row produces false (both inputs false)
- Any true input makes the result true
- OR is the most "permissive" binary operation
Key properties of OR:
- Identity: A OR false = A (false is the identity element)
- Annihilation: A OR true = true (true dominates)
- Idempotence: A OR A = A
- Commutativity: A OR B = B OR A
- Associativity: (A OR B) OR C = A OR (B OR C)
Programming examples:
// Either condition suffices
if (isAdmin || isOwner) {
showEditButton()
}
// Default value pattern
name = providedName || "Anonymous"
Real-world analogy:
OR is like a parallel circuit with two switches. Current flows (output = true) if either switch is closed (either input = true). Both must be open for the circuit to break.
Inclusive vs. Exclusive:
This OR is inclusive—true when both inputs are true. English "or" is sometimes exclusive ("soup or salad" implies one, not both). Programming uses inclusive OR; exclusive OR (XOR) is a separate operation.
Read 'A OR B' as 'at least one of A, B is true.' This includes the case where both are true. For exactly-one semantics, use XOR (covered next).
The XOR Operation (Exclusive Or)
XOR (Exclusive OR) outputs true when exactly one input is true—when the inputs differ. It captures the "one or the other, but not both" meaning of "or."
Symbols:
- Logic: A ⊕ B, A XOR B
- Programming: A ^ B (most languages)
- Electronics: A ⊕ B
The truth table for XOR:
| A | B | A XOR B |
|---|---|---|
| T | T | F |
| T | F | T |
| F | T | T |
| F | F | F |
Understanding XOR:
- True when inputs are different
- False when inputs are the same
- "Difference detector" for boolean values
Key properties of XOR:
- Identity: A XOR false = A
- Self-inverse: A XOR A = false
- Commutativity: A XOR B = B XOR A
- Associativity: (A XOR B) XOR C = A XOR (B XOR C)
- Invertibility: If C = A XOR B, then A = C XOR B
XOR's special powers:
// Swap without temporary variable
a = a ^ b // a now holds a XOR b
b = a ^ b // b now holds original a
a = a ^ b // a now holds original b
// Toggle a boolean
value = value ^ true // Flips value
// Check if two values differ
if (old ^ new) {
handleChange()
}
Real-world applications:
- Parity checking: XOR of all bits = 1 means odd number of 1s
- Encryption: Simple XOR cipher (A XOR key = ciphertext, ciphertext XOR key = A)
- Checksums: Error detection in data transmission
- Graphics: XOR drawing for cursor/selection rectangles
- RAID storage: Parity drives use XOR for redundancy
XOR is equivalent to addition modulo 2: 0⊕0=0, 0⊕1=1, 1⊕0=1, 1⊕1=0. This connection links boolean algebra to finite field arithmetic, important in cryptography and coding theory.
NAND and NOR: The Universal Gates
NAND (NOT AND) and NOR (NOT OR) are each functionally complete—any boolean function can be built using only NAND gates, or only NOR gates. This profound property makes them the building blocks of digital hardware.
NAND truth table:
| A | B | A NAND B |
|---|---|---|
| T | T | F |
| T | F | T |
| F | T | T |
| F | F | T |
NOR truth table:
| A | B | A NOR B |
|---|---|---|
| T | T | F |
| T | F | F |
| F | T | F |
| F | F | T |
Why NAND is universal:
Every other operation can be built from NAND:
NOT A = A NAND A
A AND B = (A NAND B) NAND (A NAND B)
A OR B = (A NAND A) NAND (B NAND B)
This means you can construct any boolean circuit—no matter how complex—using only NAND gates.
Why this matters for hardware:
- Manufacturing simplicity: One gate type simplifies production
- Testing: Fewer gate types mean simpler verification
- Efficiency: NAND gates are naturally efficient in CMOS technology
- Flexibility: Any logic can be implemented with the same basic building block
Historical note:
The Apollo Guidance Computer (1966) that landed humans on the Moon was built almost entirely from NOR gates—about 5,600 of them implementing 3-input NOR logic. This uniformity simplified design, testing, and manufacturing for a mission-critical system.
NAND outputs false only when both inputs are true (the opposite of AND). Think of it as 'not both'—it fails only in the single case where both conditions are met.
Building Complex Boolean Expressions
Complex boolean expressions combine multiple operations. Truth tables expand to handle any expression by evaluating step-by-step.
Example: (A AND B) OR (NOT C)
We need 3 variables → 2³ = 8 rows:
| A | B | C | A AND B | NOT C | Result |
|---|---|---|---|---|---|
| T | T | T | T | F | T |
| T | T | F | T | T | T |
| T | F | T | F | F | F |
| T | F | F | F | T | T |
| F | T | T | F | F | F |
| F | T | F | F | T | T |
| F | F | T | F | F | F |
| F | F | F | F | T | T |
Reading the table:
The expression is true in 5 out of 8 cases:
- When both A AND B are true (regardless of C)
- When C is false (regardless of A and B)
De Morgan's Laws:
These fundamental equivalences simplify boolean expressions:
NOT (A AND B) = (NOT A) OR (NOT B)
NOT (A OR B) = (NOT A) AND (NOT B)
De Morgan's laws allow you to:
- Push negation inside parentheses (flip AND↔OR)
- Simplify complex conditions
- Transform expressions into equivalent forms
Example application:
// Original
if (!(isNull || isEmpty)) { process(); }
// Apply De Morgan's: NOT(A OR B) = NOT A AND NOT B
if (!isNull && !isEmpty) { process(); }
Both forms are logically equivalent; the second is often more readable.
Simplification through truth tables:
If two expressions have identical truth tables, they're logically equivalent. This provides a mechanical way to verify simplifications or find simpler forms of complex expressions.
Standard precedence: NOT binds tightest, then AND, then OR. So 'A OR B AND C' means 'A OR (B AND C)', not '(A OR B) AND C'. When in doubt, use parentheses for clarity.
KEEP LEARNING
Keep learning for free.
Read the complete lesson, save your notes and pick up where you left off with a free account. No card needed.