xor gate using minimum number of nand gates
XOR gate An XOR gate circuit can be made from four NAND gates. In fact, both NAND and NOR gates are so-called "universal gates" and any logical function can be constructed from either NAND logic or NOR logic alone. If the four NAND gates are replaced by NOR gates, this results in an XNOR gate, which can be converted to an XOR gate by inverting the output or one of the inputs (e.g. with a fifth NOR gate). An alternative arrangement is of five NOR gates in a topology that emphasizes the construction of the function from   ( A + B ) ⋅  {\displaystyle (A+B)\cdot }    (  A ¯  +  B ¯  )  {\displaystyle ({\overline {A}}+{\overline {B}})}  (noting from de Morgan's Law that a NOR gate is, in effect, an inverted-input AND gate). Two possible configurations constructed from NAND gates and two possible configurations constructed from NOR gates are shown below.