De Morgan’s Law Calculator: Pushing a NOT Through AND and OR
About the Author

A De Morgan’s law calculator guards against the single most tempting wrong move in Boolean algebra: writing ¬(A ∧ B) = ¬A ∧ ¬B. It looks right. It’s wrong on exactly one truth-table row, which is the worst kind of wrong — the bug hides until that one input combination shows up. The correct rule flips the operator as the negation distributes: ¬(A ∧ B) = ¬A ∨ ¬B, and ¬(A ∨ B) = ¬A ∧ ¬B. The calculator above applies that rule mechanically, shows every intermediate step, and then proves the answer by checking all 2ⁿ truth-table rows. This article covers why the operator has to flip, how the same law works for sets, and where it quietly runs half the code and hardware you use every day.
Two Laws, One Move: Break the Bar, Flip the Sign
Both of Augustus De Morgan’s laws describe the same maneuver from opposite directions. In logic notation:
¬(A ∧ B) = ¬A ∨ ¬B
¬(A ∨ B) = ¬A ∧ ¬B
Digital logic courses teach the same pair with overbars and read it as a slogan: break the bar, change the sign. A long negation bar over A·B breaks into two short bars, and the · underneath it becomes a +. Set theory writes it with complements: (A ∩ B)ᶜ = Aᶜ ∪ Bᶜ and (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ. Three notations, one identity. That’s also why this page’s calculator prints its result three ways — once you see ¬A ∨ ¬B, A′ + B′, and Aᶜ ∪ Bᶜ side by side, they stop looking like three separate facts to memorize.
The Four-Row Proof
With two variables there are only four possible input combinations, so the entire proof of the first law fits in one small table. Column by column:
| A | B | A ∧ B | ¬(A ∧ B) | ¬A | ¬B | ¬A ∨ ¬B |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 |
The two bold columns agree on every row, so the expressions are equivalent — that’s the whole proof. Now compare the wrong version: ¬A ∧ ¬B produces 1, 0, 0, 0 down its column. It matches ¬(A ∧ B) on three rows out of four and disagrees only where exactly one input is true. A condition tested casually will pass those three rows and ship the fourth. If you want to build tables like this for your own expressions with more variables, the truth table calculator generates all 2ⁿ rows for anything you type.
“Not Both” Is a Weaker Claim Than “Neither”
The flip stops feeling arbitrary once you say the two sides out loud. ¬(A ∧ B) means “not both” — at least one of the two fails. ¬A ∧ ¬B means “neither” — both fail. Someone who isn’t having coffee and cake might still be having one of them; someone having neither has ruled out both. “Not both” is satisfied in three of the four scenarios, “neither” in just one. Since negating an AND gives you the weaker “at least one fails” statement, the connective on the other side has to be the weaker one too — OR. The same argument in mirror image explains the second law: denying “at least one” leaves you with “none,” which is an AND of two negations.
Negating an if-Condition Without Breaking It
This is where the law earns its keep in practice. Say a discount applies to customers who are members with a cart over $50, and you need the branch for everyone else:
// eligible: isMember && cartTotal > 50
if (!(isMember && cartTotal > 50)) { ... }
// De Morgan — same behavior, one less nesting level:
if (!isMember || cartTotal <= 50) { ... }
Two details matter. First, the && became || — that’s the law doing its job. Second, the comparison > 50 negated into ≤ 50, not < 50; negating a strict inequality always picks up the boundary value. A cart at exactly $50.00 is the row where the sloppy version misfires. Linters push this rewrite for readability, and compilers apply it silently for short-circuit evaluation — with !isMember || cartTotal <= 50, a non-member skips the cart check entirely. Paste any condition’s shape into the calculator above (as, say, !(M & C)) and the truth table confirms the rewrite before you commit it.
The Set Version: Complement of a Union, Complement of an Intersection
Swap propositions for sets and the identical structure appears. Let the universe be the ten digits U = {0, 1, …, 9}, with A = {1, 2, 3, 4} and B = {3, 4, 5, 6}. Then A ∪ B = {1, 2, 3, 4, 5, 6}, so the complement of the union is (A ∪ B)ᶜ = {0, 7, 8, 9} — four elements. Now build the right-hand side separately: Aᶜ = {0, 5, 6, 7, 8, 9} and Bᶜ = {0, 1, 2, 7, 8, 9}, and their intersection is{0, 7, 8, 9}. Same four elements, confirming (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ. The second law checks out the same way: A ∩ B = {3, 4} has an 8-element complement, exactly matching Aᶜ ∪ Bᶜ. For membership, union, and intersection operations on your own sets, the set calculator handles the element-by-element work; this page’s tool handles the symbolic side, printing results in ∩/∪/ᶜ notation directly.
Nested NOTs: What a De Morgan’s Law Calculator Does Layer by Layer
Real expressions rarely stop at two variables, and De Morgan’s law generalizes cleanly: ¬(A ∧ B ∧ C) = ¬A ∨ ¬B ∨ ¬C for any number of terms. The interesting cases are nested. Take the calculator’s default, ¬(A ∧ (B ∨ ¬C)), and push the negation inward one layer at a time:
- ¬A ∨ ¬(B ∨ ¬C) — De Morgan on the outer AND
- ¬A ∨ (¬B ∧ ¬¬C) — De Morgan on the inner OR
- ¬A ∨ (¬B ∧ C) — double negation cancels
The finished form — every negation resting on a single variable — is called negation normal form, and it’s the standard first step in logic simplification pipelines, SAT solvers, and query optimizers. Note what the law does not do: it never removes a NOT that already sits on a lone variable, and it never simplifies A ∨ ¬A to 1. Those jobs belong to other identities — complement, absorption, distribution — which the boolean algebra calculator applies when you want a fully reduced expression rather than a correctly negated one.
Why Chip Designers Lean on De Morgan Every Day
In CMOS silicon, the cheap gates are the inverting ones: a NAND takes 4 transistors while a plain AND takes 6, because AND is literally built as NAND followed by an inverter. De Morgan’s law is the bridge that lets designers use the cheap parts everywhere. Reading A′ + B′ = (A·B)′ from right to left says a NAND behaves exactly like an OR fed with inverted inputs — so any AND/OR network can be redrawn as NAND-only or NOR-only, which is why both are called universal gates. A two-level AND-OR circuit converts to all-NANDs with zero added hardware; the bubbles (inversions) introduced on one gate’s output cancel against the next gate’s inputs. If you’re minimizing a circuit before converting it, run it through the logic gate simplifier first, then apply the De Morgan rewrite here to pick your target gate family. The same trick, a century and a half old, sits between Augustus De Morgan’s 1847 formalization and every processor shipping today.



