De Morgan's Law in boolean algebra dictates that inverting the output of an AND gate is logically identical to inverting its inputs and passing them through an OR gate, and vice versa. In physical electronics and embedded firmware, this theorem changes how we map logical requirements to physical silicon, allowing designers to reduce Bill of Materials (BOM) costs by substituting unavailable NOR chips with abundant NAND chips, or simplifying nested microcontroller conditionals to shave microseconds off an interrupt service routine. People commonly confuse De Morgan's Law with the Distributive Law ($A \cdot (B + C) = A \cdot B + A \cdot C$), or they forget the critical second step: when you break the inversion bar, you must flip the operator from AND to OR (or OR to AND). Leaving the operator the same results in a catastrophic logic failure.
The Core Rule: Breaking the Bar and Flipping the Sign
Augustus De Morgan formalized these rules in the 19th century, but for modern electrical engineers and hobbyists, the law is a daily tool for logic minimization. The two primary theorems are expressed as:
Theorem 2 (NOR equivalent): NOT (A OR B) = (NOT A) AND (NOT B)
In a real circuit, applying De Morgan's Law changes your IC count, your BOM cost, and your signal propagation delay. By converting an OR function into a NAND configuration, you eliminate the need for a separate OR-gate IC. However, you must account for the physical reality of the silicon: adding a stage of inversion introduces roughly 8 to 14 nanoseconds of extra propagation delay in standard 74HC-series logic at 5V. According to Texas Instruments' Designing with Logic guidelines, managing these gate-level delays is critical when designing high-speed clock trees or synchronous data buses where skew matters.
Worked Numeric Example: 5V Logic on the Bench
Let us verify the first theorem using real voltage values on a workbench. Assume we are using standard 5V CMOS logic (like the 74HC series), where a logic HIGH is 5.0V (1) and a logic LOW is 0.0V (0). We have two inputs: A = 5.0V (1) and B = 0.0V (0).
Evaluating the Left Side: NOT (A AND B)
- Pass A (1) and B (0) into an AND gate.
- The AND gate outputs 0 (since both inputs are not HIGH).
- Pass that 0 through a NOT gate (inverter).
- Final Output: 1 (5.0V). This is the behavior of a NAND gate.
Evaluating the Right Side: (NOT A) OR (NOT B)
- Invert A (1) to get 0.
- Invert B (0) to get 1.
- Pass those inverted signals (0 and 1) into an OR gate.
- The OR gate outputs 1 (since at least one input is HIGH).
- Final Output: 1 (5.0V).
Both sides yield exactly 5.0V. As detailed in Electronics Tutorials' guide on Boolean Algebra, this equivalency holds true across all four possible input permutations (00, 01, 10, 11), proving that a NAND gate is functionally identical to an OR gate with inverted inputs.
Where You Meet This in Practice: Hardware and Code
You will encounter De Morgan's Law in two primary domains: physical logic gate substitution and embedded firmware optimization.
Hardware: The Universal NAND Gate
In PCB design or breadboard prototyping, you rarely want to stock a 74HC02 (NOR), 74HC08 (AND), and 74HC32 (OR) if you can avoid it. Because a NAND gate can be manipulated via De Morgan's Law to mimic any other basic gate, the 74HC00 (Quad 2-Input NAND) is considered a "universal gate." If your schematic calls for an OR gate, but you only have a 74HC00 left in your bin, you simply invert the inputs before feeding them into the NAND gate. You trade a few extra transistors and a slight propagation delay penalty for the convenience of keeping your BOM restricted to a single part number.
Firmware: Flattening ESP32 Conditionals
When writing C++ for an ESP32 or Arduino, deeply nested if statements with multiple negations are notoriously difficult to debug. Consider a safety interlock where a motor should not run if the limit switch is triggered AND the emergency stop is pressed:
if (!(limitSwitch.triggered && eStop.pressed)) { runMotor(); }
Applying De Morgan's Law allows you to rewrite this using positive logic, which is vastly easier for a human to read and less prone to bracket-matching errors:
if (!limitSwitch.triggered || !eStop.pressed) { runMotor(); }
While modern ARM and Xtensa compilers (like those used for the ESP32-C3 or ESP32-S3) will optimize both statements into the exact same assembly instructions, writing the De Morgan equivalent manually ensures clarity in safety-critical code reviews where compiler optimization flags might be altered.
Decision Tree: Optimizing Your Logic Gates or C++ Conditionals
Use the following decision path to determine how to apply De Morgan's Law based on your specific project constraints.
| Scenario / Constraint | Action to Take | Resulting Implementation |
|---|---|---|
| High-speed clock data path (skew < 5ns required) | Do NOT substitute gates using De Morgan's Law. Extra inversion stages add 8-14ns delay. | Use dedicated 74HC08 (AND) and 74HC32 (OR) ICs to maintain symmetrical propagation delays. |
| BOM cost reduction & low-speed control logic (< 1MHz) | Standardize on universal gates. Convert all AND/OR requirements to NAND equivalents. | Use 74HC00 exclusively. Wire inputs through spare NAND gates configured as inverters. |
| PLC Ladder Logic with limited memory/scan time | Convert series NC (Normally Closed) contacts to parallel NO (Normally Open) contacts. | Reduces the number of logic rungs and speeds up the PLC scan cycle by eliminating NOT instructions. |
| Embedded C++ safety interlocks with multiple negations | Break the outer NOT bar and flip the AND/OR operator to flatten the logic. | Use !A || !B instead of !(A && B) to improve code readability and peer-review accuracy. |
Frequently Asked Questions
Does De Morgan's Law apply to more than two variables?
Yes. The law scales to any number of inputs. For three variables, the NAND equivalent is NOT (A AND B AND C) = (NOT A) OR (NOT B) OR (NOT C). In hardware, this means a 3-input NAND gate (like one found in a 74HC10 IC) can be replaced by a 3-input OR gate provided all three inputs are inverted first.
Why do we use bubbles on logic gate symbols instead of writing 'NOT'?
The "bubble" on a logic gate symbol represents the inversion (NOT) operation. De Morgan's Law is often visualized by moving the bubbles from the output of a gate to its inputs (or vice versa) while simultaneously changing the gate shape from AND to OR. This visual bubble-pushing technique is much faster than writing out boolean equations on a whiteboard during circuit debugging.
Will applying De Morgan's Law change the power consumption of my circuit?
Minimally, but yes. In CMOS logic (like the 74HC series), power is primarily consumed during the transition states when the gate switches from HIGH to LOW or vice versa. If your De Morgan substitution adds an extra physical inverter stage to the signal path, you are adding two more CMOS transistors that must charge and discharge their parasitic capacitance. At low frequencies, this is negligible (microamps). At high frequencies (above 10MHz), the extra switching current can increase the IC's dynamic power draw by a measurable margin.






