Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
XOR Gate
Next article icon

XOR Gate

Last Updated : 07 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The XOR or Exclusive OR Gate is a special type of logic gate used in digital electronics to perform the exclusive OR operation. This gate takes two inputs and produces an output depending on the combination of the two inputs applied. This logic gate produces a high or logic 1 output when both of the inputs are dissimilar, otherwise, it produces a logic 0 output.

Operation of XOR Gate

We can explain the operation of the XOR gate as follows:

Returns 1, if the number of logical high input is odd.

Returns 0, if number of logical high input is even.

Say we have two inputs, A and B and the output is called X, then the expression is:

The Boolean expression of XOR Gate is as follows:

X = A'B + AB'

Symbol of XOR Gate

The logic symbol of XOR gate is shown in the following figure. In this figure, the variables A and B represent the input lines and A'B + AB' is the output of the XOR gate.

XOR-Gate
Symbol of XOR Gate

Truth Table of XOR Gate

The truth table of an XOR gate is given below. This table shows the relationship between inputs and output of the XOR gate. This also provides information about the operation of XOR gate for different input combinations.

ttxor
Truth Table of XOR Gate

Construction of XOR Gate Using Transistor

We can implement exclusive OR gate using transistor. Here is the circuit showing the connection of different circuit elements that are combined to implement the XOR operation.

XOR Gate using NPN Transistor
XOR Gate using NPN Transistor

Working of the Circuit

We will understand this circuit with the help of different scenarios of input in case of 2 input XOR gate:

CASE I: When both the inputs are zero. (A=0, B=0)

When both the inputs A and B are zero then transistors Q1,Q2,Q4 and Q5 are open circuit so the LED will not glow because both Q4 and Q5 are open so the negative pin of LED is not connected to the ground.

CASE II: When one input if logical high and other is logical low (A=1, B=0)

In this case we can easily see that Q4 is working as close circuit now. So the negative pin of the LED is connected to Q3 via Q4 and ultimately which is connected to ground so in this case LED will glow.

CASE III - When one input if logical high and other is logical low (A=0, B=1)

In this case we can easily see that Q5 is working as close circuit now. So the negative pin of the LED is connected to Q3 via Q5 and ultimately which is connected to ground so in this case LED will glow.

CASE IV - When both the inputs are logical high. (A=1, B=1)

In this case when both A and B are logical high then transistor Q1 and Q2 are also activated then the current will directly go from +5V junction to ground through Q1 and Q2 transistors, and will not got in the path where Q3 is connected as a result transistor Q3 will now act as open circuit and ultimately negative pin of LED is disconnected from ground so the LED will not glow.

XOR GATE Implementation using NAND GATE

Expression of XOR gate: A'.B + A.B'

To Convert the expression into NAND form perform the following:

Apply double complement: [(A’.B + A.B’)’]’

Operate internal complement: [ (A’.B)’ . (A.B’)’ ]’

Now, expression is obtained in NAND form.

Pass Input A through the first NAND Gate to get A’, now pass this A’ and B through the second NAND Gate to get (A’.B)’. Similarly, pass Input B through the third NAND Gate to get B’, now pass this B’ and A through the fourth NAND Gate to get (A.B’)’. Pass both the output (A’.B)’ and (A.B’)’ through the fifth NAND Gate to get our desired expression of XOR Gate ((A’.B)’.(A.B’)’)’ = A’B + AB’ (By De-Morgans Law).

Logic diagram

The Logical Diagram of the Following Expression is shown below

XOR_USING_NAND
XOR Gate from NAND Gate

XOR GATE Implementation using NOR GATE

To implement XOR gate from NOR gate we follow below steps

  • First, we connect both the inputs in NOR gate resulting in (A + B)’.
  • Then, after we have another two NOR gates with the inputs A, (A + B)’ and B, (A + B)’ respectively with outputs [A + (A + B)’]’ and [B + (A + B)’]’.
  • Again, the connect outputs of the above NOR gates to next NOR gate resulting in the output [A’B + AB’]’.
  • Now, the result is generated in complement form so, we connect the result as the input for last NOR gate which gives the output [AB’ + A’B].
  • The resultant of the last NOR gate gives us XOR gate.
  • So, the number of NOR gates required to implement XOR gate is 5.

below is the logic diagram for implementation of XOR gate from NOR gate:

frame_15
Implementation of XOR Gate using NOR Gate

Three Input XOR GATE

It's important to understand that there isn't a XOR gate with more than two input lines. XOR gates are typically designed with only two inputs. However, if we need an XOR gate with more than two inputs, we can create one by combining multiple two-input XOR gates. By connecting them in a specific way, we can achieve the functionality of an XOR gate with more inputs.

The logic circuit diagram of the 3-Input XOR gate is shown in the following figure. It has three input line denoted by the letter A,B,C and one output line denoted by the letter X where X=A⊕B⊕C. It can be obtained by using two 2-input XOR gates. First, perform the XOR operation on any two of the inputs. Then, XOR the result of that operation with the third input using the second XOR gate.

1
3- Input XOR Gate

The Boolean expression of N input XOR Gate is as follows:

Say we have N inputs, A0,A1,...,AN and the output is called X, the expression is:

X=A0⊕A1⊕....⊕AN

Truth Table of Three input XOR Gate

The truth table of three input XOR gate is given below:

ttxor3
Truth Table of 3-Input XOR Gate

This table shows the relationship between three inputs and one output of the XOR gate. This also provides information about the operation of XOR gate for different input combinations.

Say we have three inputs A,B and C and the output is called X, then the expression is:

X = A⊕B⊕C

Applications of XOR Gate

Here are some of the applications of the XOR Gate:

  1. Data Encryption: XOR gates are used in data encryption algorithms. As it is used to combine data with secret key to scramble it making it very difficult for unauthorized people to crack.
  2. Comparator Circuits: It is used in comparator circuit to check if the two binary values are equal or not. As for same type of both the input it gives output 0 and for different inputs it gives output 1.
  3. Binary addition and subtraction: It helps in determining sum of each bit and also combine with other logic gates to handle borrow operations.
  4. Toggle Flip flops: In T flip flops it is used to the circuit that toggles with each clock pulse passed.

Some other uses of XOR gates are in Address decoding, Security and access control, Random number generation, clock synchronization, frequency divider circuits etc.

Advantages of XOR Gate

  • It helps to detect if there are odd number of '1' in the sequence of inputs.
  • XOR gates perform the exclusive OR operation, which is a fundamental operation in digital logic.

Disadvantages of XOR Gate

  • XOR gate are complex gate circuit and upon connecting it to the circuit of our use, it causes increased power consumption and circuit complexity.
  • It leads to increase in the propagation delay of the circuit.
  • Upon increasing the number of inputs the circuit becomes more and more complex making it hard to maintain and detect errors.

Solved Example of XOR Gate

Find a single number from a series of numbers given that every element appears twice except for that one single element.

Solution: We know that XOR of two same bits gives '0' so here we can observe that if we XOR the elements then every elements which are occurring twice will become '0' and only remaining element would be our answer.

Like out of [7,2,2,3,3,4,4,5,5,6,6]

If we XOR each of the above elements then elements occurring even number of times will give '0' and elements occurring odd number of times will give the output. Ultimately we will get 7 as output as only this element is occurring once only and rest other elements are occurring even number of times.


Next Article
XOR Gate

A

anirudhkumarchaudhary01
Improve
Article Tags :
  • Digital Logic
  • Geeks Premier League
  • Electronics Engineering
  • Analog and Digital Electronics
  • Geeks Premier League 2023
  • Digital Electronics - Truth Table
  • Digital Electronics - Logic Gate

Similar Reads

    XNOR Gate
    The XNOR gate is a logic gate that performs an exclusive NOR operation. The output of the XNOR gate is logic 1 when both the inputs are logic 1 or logic 0. In other words, the output of the XNOR gate is logic 1 when both the inputs are the same(either both true or both false). For different inputs,
    9 min read
    OR Gate
    OR GATE is most widely used digital logic circuit and is known as a primitive digital electronics building block in digital logic. The output state of OR gate will be high i.e.,(1) if any of the input state is high or 1, else output state will be low i.e., 0. The Boolean Expression for the OR gate i
    7 min read
    NOR Gate
    NOR gate performs NOR(NOT OR) operation between two or more binary inputs and gives output binary signal. This is a combination of OR gate and NOT gate. It gives the output high(1) only when all of its inputs are low(0). In simple words we can say that NOR gate is the opposite (inverted) of OR Gate.
    6 min read
    CMOS Logic Gate
    The logic gates are the basic building blocks of all digital circuits and computers. These logic gates are implemented using transistors called MOSFETs. A MOSFET transistor is a voltage-controlled switch. The MOSFET acts as a switch and turns on or off depending on whether the voltage on it is eithe
    4 min read
    AND Gate
    AND gate is used to perform logical Multiplication of binary input. The Output state of the AND gate will be high(1) if both the input are high(1) ,else the output state will be low(0) if any of the input is low(0).The Boolean Expression or logic for the AND gate is the logical multiplication of inp
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences