What Is De Morgan’s Law? Boolean Logic Explained

De Morgan’s laws are two rules that show how negation (the word “not”) interacts with “and” and “or” in logic. They tell you that negating an “and” statement turns it into an “or” statement, and negating an “or” statement turns it into an “and.” These two simple rules show up everywhere: in math proofs, computer programming, digital circuit design, and even in everyday reasoning.

The Two Rules

De Morgan’s laws come as a pair. In plain English:

  • First law: “Not (A and B)” is the same as “Not A or Not B.”
  • Second law: “Not (A or B)” is the same as “Not A and Not B.”

Notice the pattern: when you push a negation inside a statement, “and” flips to “or,” and “or” flips to “and.” Both parts also get individually negated. That’s the entire idea. The laws are named after Augustus De Morgan, a 19th-century British mathematician who recognized the purely symbolic nature of algebra and helped reform mathematical logic.

How They Sound in Everyday Language

You already use De Morgan’s laws without realizing it. Consider: “I don’t like chocolate or vanilla.” That means exactly the same thing as “I don’t like chocolate and I don’t like vanilla.” You negated an “or” and it became an “and,” which is the second law in action.

For the first law, think about a number line. Saying “x is not between 2 and 3” means x is not greater than 2 or x is not less than 3. In other words, x is 2 or below, or 3 or above. The “and” connecting the two conditions (greater than 2, less than 3) flipped to “or” once you negated the whole thing.

Proving It With a Truth Table

You can verify De Morgan’s laws by checking every possible combination of true and false for two statements, p and q. Take the first law: “Not (p and q)” equals “Not p or Not q.”

When both p and q are true, “p and q” is true, so “not (p and q)” is false. On the other side, “not p” is false and “not q” is false, so “not p or not q” is also false. They match.

When p is true and q is false, “p and q” is false, so its negation is true. Meanwhile, “not q” is true, which makes “not p or not q” true. They match again. The same holds for the remaining two combinations (p false and q true, both false). In every single row, the two sides produce the same result, confirming they are logically equivalent. The second law can be verified the same way.

De Morgan’s Laws in Set Theory

The laws also apply to sets, where “and” becomes intersection, “or” becomes union, and “not” becomes the complement (everything not in a set). The set-theory versions look like this:

  • First law: The complement of (A union B) equals the complement of A intersected with the complement of B.
  • Second law: The complement of (A intersect B) equals the complement of A unioned with the complement of B.

If you picture a Venn diagram, this is intuitive. Everything outside the combined region of A and B is the same as the overlap between everything outside A and everything outside B.

How Programmers Use Them

De Morgan’s laws are practical tools for writing cleaner code. Whenever you have a complicated condition with “not” wrapped around “and” or “or,” you can rewrite it into something more readable.

For example, suppose you’re writing a function to decide whether to allow access to a website. The first draft might say: allow access if it’s not the case that the user is signed out and the IP address is untrusted. That’s a double negative wrapped around an “and,” which is hard to read. Applying De Morgan’s first law, you can rewrite it as: allow access if the user is signed in or the IP is trusted. Same logic, much clearer. “Not signed out” becomes “signed in,” “not untrusted” becomes “trusted,” and the “and” flips to “or.”

This kind of refactoring comes up constantly in if-statements, while-loop conditions, and database queries. Any time you find yourself negating a compound condition, De Morgan’s laws give you a mechanical way to simplify it.

Applications in Digital Circuit Design

In electronics, logic gates physically perform “and,” “or,” and “not” operations on electrical signals. Two of the most common and cheaply manufactured gate types are NAND (not-and) and NOR (not-or). De Morgan’s laws explain how to convert any circuit built from standard AND and OR gates into one built entirely from NAND or NOR gates.

A NAND gate outputs the negation of “A and B,” which by the first law equals “not A or not B.” A NOR gate outputs the negation of “A or B,” which by the second law equals “not A and not B.” Engineers use these equivalences to redesign circuits using fewer types of components, reducing manufacturing cost and complexity. This is one of the most direct, real-world applications of what might otherwise seem like an abstract logical principle.

The Bigger Idea: Duality

De Morgan’s laws are a specific example of a broader concept called duality. In Boolean algebra (the math behind true/false logic), every valid statement has a “dual” that you can create by swapping all the ANDs with ORs, swapping all the ORs with ANDs, and flipping all the values. The dual statement is also valid. De Morgan’s laws are the most well-known instance of this principle, but duality extends to more complex logical operators and mathematical structures as well. Recognizing this pattern lets mathematicians and engineers generate new identities for free: prove one, and its dual comes along automatically.