Logic gate: a cool term, but what does it mean? This article will introduce the concept of a logic gate as well as describe how each specific logic gate (OR, AND, XOR, NOR, NAND, XNOR, and NOT) works.

## What Is a *Logic Gate*?

First, it’s important to realize that logic gates take many forms. Even in our personal lives, we are constantly processing things through various logic gates. While our minds are optimized at doing so, we often do not realize the thought process in motion. However, it does take place.

For example, when sitting an exam, one might know that not answering a question will lead to a negative score for that question. If you thought this through and understood the concept, your mind has just processed a `NOT`

gate! In other words (pseudo code): `if `

.**NOT** {question answered} THEN negative consequences exist

Such logic gates form the building blocks for much of the world’s code as well as for electronics. While some logic gates are much more common (for example, an`AND`

or `OR`

gate is much more common than a `NAND`

or `NOR`

gate), all logic gates are sooner or later used to get a computer or electronic device to do exactly what’s required of it—to process data in a certain way.

With the help of multiple logic gates, we can construct workflows that to some extent resemble or follow human thinking. Let’s look at each one in detail.

## OR

An `OR`

logic gate is a very simple gate/construct that basically says, “*I**f my first input is true, or my second input is true, or both are true, then the outcome is true also*.” Note how we have two inputs and one output. This isn’t the case for all logic gates. If you take a look at the header image, you can see how all logic gates have two inputs—except for the `NOT`

logic gate, which has one input. All gates have one output.

In other words, we can write an `OR`

logic gate into this flowchart:

0 + 0 => 00 + 1 => 11 + 0 => 11 + 1 => 1

Here,`0`

represents `false`

and `1`

represents `true`

. As you can see, the only way that our output could ever be `false`

(i.e. `0`

) is if both inputs were also`false`

. In all other cases, the output of our `OR`

gate will be `true`

.

Interestingly, if both inputs are `true`

, the output will also be `true`

. This is a little offset from a human thinking about `OR`

, as the word *or* is often associated with one or the other.

## AND

Similar to our `OR`

logic gate, the `AND`

logic gate will process two inputs resulting in one output, but this time, we’re looking for both inputs to be `true`

for the outcome to become `true`

. In other words, our logic works like this:

0 + 0 => 00 + 1 => 01 + 0 => 01 + 1 => 1

All other gates (except for the `NOT`

gate) are a little more tricky to comprehend, but stay tuned.

## XOR

The `XOR`

gate is also sometimes called `EOR`

or `EXOR`

. The correct lingo for an `XOR`

gate is *Exclusive OR*. If you remember our previous example, we were a little surprised that `true`

and `true`

would still lead to `true`

, somewhat unlike human reasoning.

Welcome to `XOR`

(**exclusive** OR), which solves this problem, much in line with standard human reasoning. This logic gate works like this:

0 + 0 => 00 + 1 => 11 + 0 => 11 + 1 => 0

The input and output are the same as our `OR`

gate, but this time, the input really does need to be *exclusive*. If the input is `true`

and `true`

, the output is `false`

.

## NOR

Remember our earlier `NOT`

example? We’ve reversed things. It’s somewhat similar to the `NOR`

gate, which is basically a `NOT-OR`

gate where `OR`

is of the same logic as we discussed above for the `OR`

gate.

In other words, you might think about it like this: “*A**nything which is not an OR-situation (i.e. true and false mixed or true and true alike to our OR gate example, even if not immediately logical to humans) renders a true outcome, and all the rest results in a false outcome.*”

This leads to the following `NOR`

gate logic:

0 + 0 => 10 + 1 => 01 + 0 => 01 + 1 => 0

Armed with this knowledge, we can take a look at the `NAND`

gate:

## NAND

Akin to `NOR`

,`NAND`

could be read as `NOT-AND`

, and thus, anything that’s normally an `AND`

has to be false (i.e. `NOT-AND`

). This leads to the following outcome:

0 + 0 => 10 + 1 => 11 + 0 => 11 + 1 => 0

As in each of the first three cases, a full `AND`

(which would be `true`

and `true`

) isn’t present. Hence, the outcome is `true`

(`1`

). For the last input, `true`

and `true`

, a full `AND`

is present and thus (due to the `NOT`

component, the `N`

in `NAND`

), the outcome is false.

In this image, we see an SN7400N chip that has four logic gates, namely,`NAND`

gates. Thus, a higher voltage (a `true`

/`1`

state) on pins 1 and 2 (bottom left) will lead to a low voltage (likely 0V) state on pin 3 at any given time. And if one of the two or both pins (1+2) would become low voltage, pin 3 would start providing a higher voltage.

## XNOR

Thinking back on the `OR`

, `NOR`

, and `XOR`

gates, the `XNOR`

gate is a combination of all of them. Basically, an *Exclusive NOT-OR* or `Exclusive NOR`

gate. The logic is as follows:

0 + 0 => 10 + 1 => 01 + 0 => 01 + 1 => 1

In other words, the reverse of a`XOR`

gate outcome. Yes, it can get a little complex to follow.

## NOT

We already briefly introduced the `NOT`

gate earlier with our human equivalent example. The `NOT`

gate basically reverses whatever input is given to it. If you provide `true`

as the input, the output will be `false`

and vice versa. Our logic table is simple:

0 => 11 => 0

This gate is often used in combination with other gates.

## Logic Gates in Computer Code

A simple example of a `NOT`

gate can be seen in the following Bash code:

if [ ! true ]; then echo 'false'; else echo 'true'; fi

In this example, we basically say:`if not true, then echo false, otherwise echo true`

. Because we use a `NOT`

gate, the output is true even though `not true`

is false.

As you can see, code easily gets a little confusing to read and develop when you use `NOT`

gates, and especially so when combining them with `AND`

or `OR`

gates. But practice makes perfect, and seasoned developers love to use complex gate conditional statements.

In many coding languages, a logical `OR`

gate is represented by the `||`

idiom, and an`AND`

logic gate is often represented by the `&&`

idiom. A `NOT`

gate is usually represented by the `!`

symbol.

## Wrapping up

In this article, we discussed the OR, AND, XOR, NOR, NAND, XNOR, and NOT logic gates. We also covered how logic gates mimic human thinking and how they can help us write complex pieces of programming logic in a computer program. We also had a brief look at logic gates as used in computer code.

If you enjoyed reading this article, take a look at our From 0 to F: Hexadecimal and Bits, Bytes, and Binary articles, which will help you understand how computers work internally.

READ NEXT

- › What Is Tesla Dog Mode, and How Does It Work?
- › How to Hide Posts From Someone on Instagram
- › How to Connect a Wireless Controller to Your Nintendo Switch
- › Xbox App Won’t Open in Windows? 9 Fixes
- › How to Delete a Video on TikTok
- › How to Delete Facebook Notifications

## FAQs

### How Logic Gates Work: OR, AND, XOR, NOR, NAND, XNOR, and NOT? ›

Difference between XOR and XNOR

In the truth table, **XOR gives a logical value of 1 when both the inputs are different**. In the truth table, XNOR gives a logical value of 1 when both the inputs are the same. In the symbolic representation of the XOR gate, there is no circle in front of the circuit symbol.

**What is the difference between XOR and XNOR logic gates? ›**

Difference between XOR and XNOR

In the truth table, **XOR gives a logical value of 1 when both the inputs are different**. In the truth table, XNOR gives a logical value of 1 when both the inputs are the same. In the symbolic representation of the XOR gate, there is no circle in front of the circuit symbol.

**What are the different logic gates and how do they work? ›**

Basic logic gates. There are seven basic logic gates: **AND, OR, XOR, NOT, NAND, NOR, and XNOR**. The AND gate is so named because, if 0 is called "false" and 1 is called "true," the gate acts in the same way as the logical "and" operator.

**What is the difference between an OR logic gate and an XOR logic gate? ›**

**OR is true if at least one of the operands is true.** **XOR is true if exactly one of the operands is true**.

**What is the difference between NOR and XOR and OR gate? ›**

XOR: **XOR gate or Exclusive-OR gate is a special type of logic gate which gives 0 as output if both of the inputs are either 0 or 1, otherwise it gives 1**. XNOR: XNOR gate or Exclusive-NOR gate is a special type of logic gate which gives 1 as output when both the inputs are either 0 or 1, otherwise it gives 0.

**What is the purpose of XOR and XNOR gate? ›**

The XOR output is asserted whenever an odd number of inputs are asserted, and the XNOR is asserted whenever an even number of inputs are asserted: the XOR is an odd detector, and the XNOR, an even detector. **Xor gate can be used as a “controlled inverter”**.

**What is the purpose of XNOR gate? ›**

The XNOR logic gates are used in **error detecting circuits which are to detect Odd parity or even parity bits in digital data transmission circuits**. XNOR gate is mainly used in arithmetic and encryption circuits.

**How does a NAND circuit work? ›**

NAND gates **help detect if a single input to a digital system has gone low**. For example, a simple security system consisting only of NAND gates could be used to monitor the status of sensors connected to windows and/or doors. If a window/door is closed, the sensor sends a logical “1” signal to the security system.

**What is the difference between NOR and NAND gates? ›**

**A NAND gate is a universal logic gate which performs the negated logical multiplication.** **A NOR gate is a universal logic gate which performs the negated logical addition**. NAND gate can be implemented by using an AND gate followed by a NOT gate. NOR gate can be implemented by using an OR gate followed by a NOT gate.

**How do XOR gates work? ›**

An XOR gate implements an exclusive OR, i.e., a true output result if one, and only one, of the gate inputs, is true. If both the inputs are false (either 0 or LOW) or if both are true, there results in a false output.

### What is the difference between XOR and NAND? ›

**An XOR gate is made by connecting four NAND gates** as shown below. This construction entails a propagation delay three times that of a single NAND gate. , noting from de Morgan's Law that a NAND gate is an inverted-input OR gate. This construction uses five gates instead of four.

**What are the 3 types of logic gates? ›**

All digital systems can be constructed by only three basic logic gates. These basic gates are called **the AND gate, the OR gate, and the NOT gate**. Some textbooks also include the NAND gate, the NOR gate and the EOR gate as the members of the family of basic logic gates.

**What is NAND gate and XOR gate? ›**

The output of Ex-OR gate is '1' when an odd number of ones present at the inputs. Hence, the output of Ex-OR gate is also called as an odd function. NAND gate - **It is a digital circuit that has two or more inputs and produces an output, which is the inversion of logical AND of all those inputs**.

**What is an example of an XOR gate in real life? ›**

Real World Example:

A fun example of an XOR gate would be **a game show buzzer**. If two contestants buzz in, only one of them, the ﬁrst to buzz, will activate the circuit. The other contestant will be “locked out” from buzzing. To learn more about logic, click here.

**What is the symbol for a NAND gate? ›**

The Boolean expression for a logic NAND gate is represented by **a single dot or full stop symbol, ( . )** **followed by a line or Overline, ( ‾‾ )** over the expression to imply the NOT or logical negation of the NAND gate.

**Where are XNOR gates used? ›**

Ex-NOR gates are used mainly in **electronic circuits that perform arithmetic operations and data checking such as Adders, Subtractors or Parity Checkers, etc**.

**Why XOR is used? ›**

The primary reason XOR is so useful in cryptography is because **it is "perfectly balanced"**; for a given plaintext input 0 or 1, the ciphertext result is equally likely to be either 0 or 1 for a truly random key bit. The table below shows all four possible pairs of plaintext and key bits.

**Is XNOR the opposite of XOR? ›**

XOR stands for eXclusive OR. As can be seen, **the output values of XNOR are simply the inverse of the corresponding output values of XOR**.

**Are XOR and XNOR universal gates? ›**

**XOR and XNOR are the derived gates**. A universal gate is a gate that can implement any Boolean function without the need to use any other gate type. NAND and NOR gates are universal gates.

**What is the difference between ex or gate and ex NOR gate? ›**

Hint: An EX-OR gate is a digital logic gate which gives a true output when the number of inputs is odd only. Whereas, **EX-NOR gate is just an EX-OR gate followed by a NOT gate which gives a true output only when the number of inputs is even**.

### What is the conclusion of XOR and XNOR gate? ›

While the Exclusive NOR gate only inverts the values of the XOR gate. CONCLUSION There are two remaining gates of the primary electronics logic gates: XOR, which stands for Exclusive OR, and XNOR, which stands for Exclusive NOR. In an XOR gate, **the output is HIGH if one, and only one, of the inputs is HIGH**.