LogicGates.org Open the simulatorSimulator

De Morgan's laws

Two rules for moving a NOT through a bracket. Negate an AND and you get an OR of negations; negate an OR and you get an AND of negations. Negate every term, swap the operator. That is the whole of it, and it is one of the most used identity in digital logic.

First law
¬(A ∧ B) = ¬A ∨ ¬B
NOT (A AND B) is (NOT A) OR (NOT B).
Second law
¬(A ∨ B) = ¬A ∧ ¬B
NOT (A OR B) is (NOT A) AND (NOT B).

De Morgan's first and second law

Each law with its truth table proof. Two variables have four combinations, so checking all four proves the law.

First law

¬(a ∧ b) = ¬a ∨ ¬b

The negation of an AND is the OR of the negations.

A NAND gate is an OR gate with both inputs inverted.

Proof
ab ¬(a ∧ b) ¬a ∨ ¬b
0 0 1 1
0 1 1 1
1 0 1 1
1 1 0 0

Both columns match on all 4 rows, so the identity holds.

Second law

¬(a ∨ b) = ¬a ∧ ¬b

The negation of an OR is the AND of the negations.

A NOR gate is an AND gate with both inputs inverted.

Proof
ab ¬(a ∨ b) ¬a ∧ ¬b
0 0 1 1
0 1 0 0
1 0 0 0
1 1 0 0

Both columns match on all 4 rows, so the identity holds.

The same laws in every notation

Textbooks, datasheets and programming languages write the same two laws in different symbols. Every row below is checked by this site's expression engines.

Notation First law Second law
Logic ¬(A ∧ B) = ¬A ∨ ¬B ¬(A ∨ B) = ¬A ∧ ¬B
Boolean, overbar not (A · B) = not A + not B not (A + B) = not A · not B
Boolean, prime (AB)' = A' + B' (A + B)' = A'B'
C, Java, JS !(a && b) ≡ !a || !b !(a || b) ≡ !a && !b
Python not (a and b) ≡ not a or not b not (a or b) ≡ not a and not b
Set theory (A ∩ B)ᶜ = Aᶜ ∪ Bᶜ (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ

The bar form is read "break the line, change the sign": cut the bar over A · B into a bar over each letter, and the · under the cut becomes +. In the code rows, ≡ means the two sides always give the same result; it is not an operator you can type. Writing == between them would need brackets round each side, because == binds tighter than || and or.

Proof of De Morgan's theorem

The truth tables above are one proof: with two variables there are only four cases, and checking every case is a proof. The algebraic proof uses the fact that a value has exactly one complement. If ¬a ∨ ¬b ORed with a ∧ b always gives 1, and ANDed with it always gives 0, then ¬a ∨ ¬b is the complement of a ∧ b, which is ¬(a ∧ b).

Together they cover every case

OR the two sides. If the result is always 1, no row is missing from both.

  1. (a ∧ b) ∨ (¬a ∨ ¬b)
  2. (a ∨ ¬a ∨ ¬b) ∧ (b ∨ ¬a ∨ ¬b) Distributive law: OR over AND
  3. (1 ∨ ¬b) ∧ (1 ∨ ¬a) Complement: a ∨ ¬a = 1 and b ∨ ¬b = 1
  4. 1 ∧ 1 Annulment: 1 ∨ x = 1
  5. 1 Identity

They never overlap

AND the two sides. If the result is always 0, no row is in both.

  1. (a ∧ b) ∧ (¬a ∨ ¬b)
  2. (a ∧ b ∧ ¬a) ∨ (a ∧ b ∧ ¬b) Distributive law: AND over OR
  3. (0 ∧ b) ∨ (a ∧ 0) Complement: a ∧ ¬a = 0 and b ∧ ¬b = 0
  4. 0 ∨ 0 Annulment: 0 ∧ x = 0
  5. 0 Identity

So ¬(a ∧ b) = ¬a ∨ ¬b. The second law has the same proof with every AND and OR swapped and every 1 and 0 swapped, which is the duality principle of boolean algebra: any law stays true when you swap them.

How to apply De Morgan's law step by step

The rule is mechanical, and it is easiest to remember as three moves on the bracket:

  1. Take the NOT off the bracket. The bracket no longer has a bar over it.
  2. Negate every term inside. A term that was already negated now has two NOTs, which cancel.
  3. Swap the operator. Every AND between those terms becomes OR, and every OR becomes AND.

When brackets are nested, work from the outside in. The outer NOT sees the inner bracket as one term, so it gets a NOT of its own and waits. Then apply the law to that inner bracket in turn. The older mnemonic is "break the line, change the sign": the overbar breaks into pieces, and the operator under the break flips.

Worked example: Simplify ¬(a ∨ ¬b) ∨ ¬(a ∨ b)

Two negated brackets. Clear them with De Morgan, and the rest falls out.

  1. ¬(a ∨ ¬b) ∨ ¬(a ∨ b)
  2. (¬a ∧ ¬¬b) ∨ (¬a ∧ ¬b) De Morgan on each bracket: negate every term, OR becomes AND
  3. (¬a ∧ b) ∨ (¬a ∧ ¬b) Double negation: ¬¬b is b
  4. ¬a ∧ (b ∨ ¬b) Distributive law, taking out the common ¬a
  5. ¬a ∧ 1 Complement: b ∨ ¬b = 1
  6. ¬a Identity: x ∧ 1 = x

Every line has the same truth table as the first, and the last one, ¬a, is also what the boolean algebra calculator reaches on its own.

Worked examples

Six derivations, each one a step at a time with the law named at every line. Every step is checked against the starting expression by the same engine that runs the tools on this site.

A NOT over an AND

The basic move, followed by the tidy-up that nearly always comes with it.

  1. ¬(a ∧ ¬b)
  2. ¬a ∨ ¬¬b De Morgan: negate each term, AND becomes OR
  3. ¬a ∨ b Double negation: ¬¬b is b

A NOT over a longer OR

With three terms the rule is the same: every term is negated and every operator is swapped.

  1. ¬(a ∨ ¬b ∨ c)
  2. ¬a ∧ ¬¬b ∧ ¬c De Morgan: negate each term, OR becomes AND
  3. ¬a ∧ b ∧ ¬c Double negation

Nested brackets, outside in

Apply the law to the outermost NOT first. The inner bracket comes along as one term, and gets its own turn.

  1. ¬((a ∧ b) ∨ c)
  2. ¬(a ∧ b) ∧ ¬c De Morgan on the outer OR; the bracket is a single term
  3. (¬a ∨ ¬b) ∧ ¬c De Morgan on the inner AND

The complement of a function

Negating a sum of products gives a product of sums. This is how you write ¬F when you already have F.

  1. ¬((a ∧ b) ∨ (¬a ∧ c))
  2. ¬(a ∧ b) ∧ ¬(¬a ∧ c) De Morgan on the OR
  3. (¬a ∨ ¬b) ∧ (¬¬a ∨ ¬c) De Morgan on each AND
  4. (¬a ∨ ¬b) ∧ (a ∨ ¬c) Double negation

An OR gate from NAND gates

Read backwards, the law turns an OR into a NAND with inverted inputs, which is how NAND builds everything.

  1. a ∨ b
  2. ¬¬(a ∨ b) Double negation, added on purpose
  3. ¬(¬a ∧ ¬b) De Morgan on the inner NOT: one NAND fed by two inverters

Clearing a negated bracket before simplifying

Simplification needs the NOTs on single variables. De Morgan pushes them there; then the ordinary laws apply.

  1. ¬(¬a ∨ (b ∧ ¬c))
  2. a ∧ ¬(b ∧ ¬c) De Morgan on the OR, with ¬¬a written as a
  3. a ∧ (¬b ∨ c) De Morgan on the remaining AND
  4. (a ∧ ¬b) ∨ (a ∧ c) Distributive law, into sum of products form

Want to see one on your own expression? The boolean algebra calculator shows every law it applies, and can confirm that any two of the lines above are equivalent.

De Morgan's law for n variables

The laws hold for any number of terms, because a ∧ b ∧ c is just (a ∧ b) ∧ c and the two-variable law can be applied twice. In practice you treat the whole chain at once: negate every term, swap every operator.

¬(x₁ ∧ x₂ ∧ … ∧ xₙ) = ¬x₁ ∨ ¬x₂ ∨ … ∨ ¬xₙ

¬(x₁ ∨ x₂ ∨ … ∨ xₙ) = ¬x₁ ∧ ¬x₂ ∧ … ∧ ¬xₙ

The three and four variable forms, each proved by its full truth table of 8 or 16 rows. The test suite checks every width up to eight.

¬(a ∧ b ∧ c) = ¬a ∨ ¬b ∨ ¬c

A three input NAND is a three input OR with every input inverted.

Proof
abc ¬(a ∧ b ∧ c) ¬a ∨ ¬b ∨ ¬c
0 0 0 1 1
0 0 1 1 1
0 1 0 1 1
0 1 1 1 1
1 0 0 1 1
1 0 1 1 1
1 1 0 1 1
1 1 1 0 0

Both columns match on all 8 rows, so the identity holds.

¬(a ∨ b ∨ c) = ¬a ∧ ¬b ∧ ¬c

A three input NOR is a three input AND with every input inverted.

Proof
abc ¬(a ∨ b ∨ c) ¬a ∧ ¬b ∧ ¬c
0 0 0 1 1
0 0 1 0 0
0 1 0 0 0
0 1 1 0 0
1 0 0 0 0
1 0 1 0 0
1 1 0 0 0
1 1 1 0 0

Both columns match on all 8 rows, so the identity holds.

¬(a ∧ b ∧ c ∧ d) = ¬a ∨ ¬b ∨ ¬c ∨ ¬d

A four input NAND is a four input OR with every input inverted.

Proof
abcd ¬(a ∧ b ∧ c ∧ d) ¬a ∨ ¬b ∨ ¬c ∨ ¬d
0 0 0 0 1 1
0 0 0 1 1 1
0 0 1 0 1 1
0 0 1 1 1 1
0 1 0 0 1 1
0 1 0 1 1 1
0 1 1 0 1 1
0 1 1 1 1 1
1 0 0 0 1 1
1 0 0 1 1 1
1 0 1 0 1 1
1 0 1 1 1 1
1 1 0 0 1 1
1 1 0 1 1 1
1 1 1 0 1 1
1 1 1 1 0 0

Both columns match on all 16 rows, so the identity holds.

¬(a ∨ b ∨ c ∨ d) = ¬a ∧ ¬b ∧ ¬c ∧ ¬d

A four input NOR is a four input AND with every input inverted.

Proof
abcd ¬(a ∨ b ∨ c ∨ d) ¬a ∧ ¬b ∧ ¬c ∧ ¬d
0 0 0 0 1 1
0 0 0 1 0 0
0 0 1 0 0 0
0 0 1 1 0 0
0 1 0 0 0 0
0 1 0 1 0 0
0 1 1 0 0 0
0 1 1 1 0 0
1 0 0 0 0 0
1 0 0 1 0 0
1 0 1 0 0 0
1 0 1 1 0 0
1 1 0 0 0 0
1 1 0 1 0 0
1 1 1 0 0 0
1 1 1 1 0 0

Both columns match on all 16 rows, so the identity holds.

De Morgan's law in logic gates

On a schematic the laws are drawn rather than written. The small circle on a gate's pin, the bubble, means invert. Each law says that two drawings are the same part:

NAND ¬(a ∧ b)
=
OR with inverted inputs ¬a ∨ ¬b
A NAND gate is an OR gate with both inputs inverted.
NOR ¬(a ∨ b)
=
AND with inverted inputs ¬a ∧ ¬b
A NOR gate is an AND gate with both inputs inverted.

Put another way, De Morgan says you may move a bubble from the output of a gate to all of its inputs as long as you swap the gate's shape at the same time. This is called bubble pushing.

  • A NAND gate, an AND with a bubbled output, is the same part as an OR with both inputs bubbled: ¬(a ∧ b) = ¬a ∨ ¬b.
  • A NOR gate, an OR with a bubbled output, is an AND with both inputs bubbled: ¬(a ∨ b) = ¬a ∧ ¬b.
  • Two bubbles on one wire cancel, so a NAND driving a gate with bubbled inputs can be redrawn as a plain AND driving a plain gate.

Engineers use this to make a schematic read the way the design was thought about, with active-low signals shown as bubbles rather than as extra inverters. It is also why NAND and NOR are universal: the OR that NAND seems to lack is a NAND with its inputs inverted, which is the "OR gate from NAND gates" example above. The NAND and NOR converter applies the laws to a whole expression and counts the gates, and the logic gate symbols page has every gate in both drawing standards.

De Morgan's law for sets

The same two laws hold for sets, with intersection for AND, union for OR and the complement for NOT. An element is in A ∩ B when it is in A and in B, so the two subjects are one algebra in different symbols.

(A ∩ B)ᶜ = Aᶜ ∪ Bᶜ

(A ∪ B)ᶜ = Aᶜ ∩ Bᶜ

In words: whatever is not in both sets is missing from at least one of them, and whatever is in neither set is outside A and outside B. Worked out with U = {1, 2, 3, 4, 5, 6, 7, 8}, A = {1, 2, 3, 4} and B = {3, 4, 5, 6}:

Set Meaning Elements
A ∩ B In both {3, 4}
(A ∩ B)ᶜ Not in both {1, 2, 5, 6, 7, 8}
Aᶜ Not in A {5, 6, 7, 8}
Bᶜ Not in B {1, 2, 7, 8}
Aᶜ ∪ Bᶜ Not in A, or not in B {1, 2, 5, 6, 7, 8}

(A ∩ B)ᶜ and Aᶜ ∪ Bᶜ are both {1, 2, 5, 6, 7, 8}, and the second law checks out the same way: (A ∪ B)ᶜ and Aᶜ ∩ Bᶜ are both {7, 8}.

See it shaded: the Venn diagram generator draws (A ∩ B)ᶜ and gives its shortest equivalent, and the set notation page explains every symbol used here.

Common mistakes

The error nearly everyone makes once is to push the NOT inside the bracket and leave the operator alone, writing ¬(a ∧ b) as ¬a ∧ ¬b. The table shows where it goes wrong.

a b ¬(a ∧ b) ¬a ∧ ¬b
0 0 1 1
0 1 1 0
1 0 1 0
1 1 0 0

The two differ on 2 of 4 rows. "Not both a and b" is true whenever either one is missing; "not a and not b" needs both to be missing. The first is an OR of the negations, and only the OR is right.

Negating only some of the terms

¬(a ∨ b) is not ¬a ∧ b (wrong on 2 of 4 rows)

It is ¬a ∧ ¬b

Every term inside the bracket gets a NOT, not only the first.

Breaking the bar only partway

¬(a ∧ b ∧ c) is not ¬a ∨ ¬b ∧ ¬c (wrong on 2 of 8 rows)

It is ¬a ∨ ¬b ∨ ¬c

When the bar breaks, it breaks over every operator beneath it. Swap one AND and leave the other, and the function changes.

Losing the grouping inside the bracket

¬(a ∨ b ∧ c) is not ¬a ∧ ¬b ∨ ¬c (wrong on 2 of 8 rows)

It is ¬a ∧ (¬b ∨ ¬c)

AND binds tighter than OR, so the bracket holds a ∨ (b ∧ c): two terms, not three. Apply the law to the OR, then to the inner AND, and keep the bracket the swap creates.

Where the name comes from

Augustus De Morgan (1806–1871) was a British mathematician and logician, a contemporary and correspondent of George Boole, and he stated the laws formally in his Formal Logic of 1847; the algebraic notation used here came with Boole's algebra that followed. The observation itself is much older: medieval logicians knew it, and William of Ockham wrote out the same rule in words in the fourteenth century. What De Morgan added was a formal statement within symbolic logic, and Boolean algebra then made it mechanical enough to build circuits with.

Questions about De Morgan's laws

What are De Morgan's laws?

Two identities in boolean algebra that say how a NOT moves through a bracket. Negating an AND gives the OR of the negated terms: ¬(A ∧ B) = ¬A ∨ ¬B. Negating an OR gives the AND of the negated terms: ¬(A ∨ B) = ¬A ∧ ¬B. In short, negate every term and swap AND for OR.

What is De Morgan's law in logic gates?

The same two laws read as gates: a NAND gate is an OR gate with both inputs inverted, and a NOR gate is an AND gate with both inputs inverted. That is what lets any circuit be rebuilt from NAND gates alone or from NOR gates alone, and what engineers are doing when they push inversion bubbles around a schematic.

How do you prove De Morgan's law?

With a truth table: two variables have only four combinations, and ¬(A ∧ B) and ¬A ∨ ¬B give the same output on all four. Or with algebra: show that ¬A ∨ ¬B ORed with A ∧ B is always 1 and ANDed with it is always 0. Only the complement of A ∧ B does both, so ¬A ∨ ¬B is that complement.

How do you apply De Morgan's law step by step?

Find the NOT that covers a bracket. Remove it, put a NOT on every term inside the bracket instead, and swap the operator between the terms: AND becomes OR, OR becomes AND. If a term was already negated it now has two NOTs, which cancel. Work from the outermost bracket inwards, treating any inner bracket as a single term until it is its own turn.

Do De Morgan's laws work for more than two variables?

Yes. ¬(A ∧ B ∧ C) = ¬A ∨ ¬B ∨ ¬C, and the same for OR, for any number of terms. It follows from applying the two-variable law repeatedly, since A ∧ B ∧ C is (A ∧ B) ∧ C. The tables on this page prove the three and four variable forms directly.

What is De Morgan's law for sets?

The complement of an intersection is the union of the complements, (A ∩ B)ᶜ = Aᶜ ∪ Bᶜ, and the complement of a union is the intersection of the complements, (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ. They are the same laws as in logic, because being in A ∩ B means being in A AND in B.

Why is ¬(A ∧ B) not the same as ¬A ∧ ¬B?

Take A = 1 and B = 0. Then A ∧ B is 0, so ¬(A ∧ B) is 1; but ¬A ∧ ¬B is 0 ∧ 1, which is 0. The NOT cannot simply be distributed inside the bracket; the operator has to flip as well. "Not both" means "at least one is missing", which is an OR.

Who was De Morgan?

Augustus De Morgan, a British mathematician and logician, who stated the laws formally in 1847, alongside George Boole's work. The idea itself is older: medieval logicians, William of Ockham among them, had written out the same rule in words.