CNOT vs Toffoli Gate: The Quantum Logic Explained Simply

Key Insights
- One control vs two: CNOT acts on 2 qubits and has 4 computational-basis inputs. Toffoli acts on 3 qubits and has 8. Each gate flips its target in exactly two rows of its truth table.
- Different logic, not just an extra wire: CNOT computes XOR (a โ b). Toffoli computes c โ (a โง b), which puts AND logic inside a reversible gate. Circuits built only from CNOT and NOT gates can never produce AND.
- Toffoli has a proven CNOT cost: An exact Toffoli built from CNOTs and single-qubit gates needs at least 6 CNOTs when no extra qubits are used. An n-qubit version needs at least 2n, according to Shende and Markov’s proof of the Toffoli gate’s CNOT cost.
- A cheaper variant exists: A simplified Toffoli that is correct only up to relative phases needs just 3 CNOTs, as described in IBM’s Qiskit reference for the simplified Toffoli gate. It can be used where the result is later uncomputed.
- Both gates support universality: CNOT plus single-qubit gates can build any quantum operation, as shown in the foundational paper on elementary gates for quantum computation. Toffoli plus one basis-changing gate such as Hadamard is also enough for universal quantum computation.
- Entanglement depends on the input: Hadamard plus CNOT turns |00โฉ into the Bell state (|00โฉ + |11โฉ)/โ2. But CNOT on |10โฉ simply returns |11โฉ, which is not entangled. Toffoli likewise entangles only some inputs.
- Both gates are their own inverse: Applying either gate twice returns any state to where it started. Circuits use this to compute temporary results on auxiliary qubits and then cleanly erase them.
- They work best together in arithmetic: Reversible adders use Toffoli gates for carry bits and CNOTs for sum bits. The Cuccaro ripple-carry quantum adder needs only a single ancillary qubit.
- Choose by control logic, then check the hardware: Use CNOT for one-control flips and two-qubit interactions. Use Toffoli when two controls must both be 1. Real implementation cost depends on the device’s native gates.
CNOT and Toffoli are two of the most widely used quantum logic gates. In the CNOT vs Toffoli gate comparison, the core difference is how many control qubits each one uses.
The CNOT gate is a two-qubit gate with one control qubit and one target qubit. The Toffoli gate is a three-qubit gate with two control qubits and one target qubit.
In both gates, the target flips only when the required control condition is met. That rule makes them key tools for quantum circuits, reversible logic and quantum algorithm design.
This guide compares their behavior, truth tables, circuit symbols and applications, so you know exactly when to use each.
How do CNOT and Toffoli Gates Work?
CNOT and Toffoli are controlled quantum gates. A control qubit acts like a switch. The target qubit receives the action, which is a NOT that flips 0 to 1 or 1 to 0.
CNOT checks one control, while Toffoli checks two. On computational-basis inputs, meaning plain 0s and 1s such as |01โฉ, both behave like reversible classical logic.
Both gates also act on quantum superpositions, and both are reversible. Their behavior is written in ket notation, where |a, bโฉ lists each qubit’s value in order.

What is a CNOT Gate?
The controlled-NOT gate in quantum computing flips its target qubit when the control qubit is 1. If the control is 0, the target stays unchanged.
With two qubits, there are four computational-basis inputs: |00โฉ, |01โฉ, |10โฉ and |11โฉ. The control passes through untouched. The target becomes the XOR of the original control and target:
|a, bโฉ โ |a, a โ bโฉ
Here, โ means XOR, which outputs 1 when exactly one input is 1. So b โ 1 flips b, while b โ 0 leaves it alone.
What is a Toffoli Gate?
The Toffoli gate is also called the controlled-controlled-NOT or CCNOT gate. It flips its target only when both control qubits are 1. Any other combination leaves the target unchanged.
This three-qubit quantum gate has two controls (a and b) and one target (c). That gives eight computational-basis inputs, from |000โฉ to |111โฉ. Its rule is:
|a, b, cโฉ โ |a, b, c โ (a โง b)โฉ
Here, โง means AND, which is 1 only when a and b are both 1. The โ then XORs that result into the target. Both control qubits remain unchanged.
Key point: CNOT flips its target when its single control is 1; Toffoli flips its target only when both controls are 1.
CNOT vs Toffoli Gate: What Are the Key Differences?
Both gates are reversible controlled operations. They differ in qubit count, control conditions, circuit complexity and the logic functions they implement. The table below compares them by how they act on computational-basis states.
| Feature | CNOT Gate | Toffoli Gate |
|---|---|---|
| Full name | Controlled-NOT | Controlled-controlled-NOT |
| Common abbreviation | CNOT | CCNOT |
| Number of qubits | 2 | 3 |
| Number of control qubits | 1 | 2 |
| Number of target qubits | 1 | 1 |
| Target flips when | Control is 1 | Both controls are 1 |
| Main Boolean operation | Target XOR control | Target XOR (control 1 AND control 2) |
| Reversible | Yes | Yes |
| Computational-basis inputs | 4 | 8 |
| Common use | Entanglement, controlled operations, quantum circuits | Reversible logic, arithmetic circuits, multi-controlled operations |
How do Their Control Conditions Differ?
Control conditions decide when each gate acts. CNOT tests one bit and Toffoli tests two. In the computational basis, the target responds as follows:
- CNOT, control 0: the target is unchanged.
- CNOT, control 1: the target flips.
- Toffoli, controls 00, 01 or 10: the target is unchanged.
- Toffoli, controls 11: the target flips.
Neither gate changes its control qubits in the computational-basis description. Only the target can change.
Is the Toffoli Gate Just a More Powerful CNOT Gate?
No. Toffoli implements a different three-qubit operation; it is not simply a CNOT with an extra wire. Its target responds to the AND of two controls, which no single CNOT can check.
Circuits made only of CNOT and NOT gates can build XOR-style logic but never AND. Toffoli supplies that missing piece while staying reversible.
Both remain key building blocks, and larger multi-qubit operations are often assembled from simpler gates. What a Toffoli costs in practice depends on the hardware and its native gates.
Key point: The Toffoli gate’s additional control condition enables reversible logic that a single CNOT cannot implement on its own.
What is the CNOT Gate Truth Table?
The CNOT gate truth table lists all four two-bit inputs and their outputs. The control bit never changes, and the target flips only when the control is 1.
| Control (A) | Target (B) | Output A | Output B |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 |
How to Read the CNOT Truth Table
Read each row with the input on the left and the output on the right. Check the control first, because it alone decides whether the target flips:
- 00 stays 00 because the control is 0.
- 01 stays 01 because the control is 0.
- 10 becomes 11 because the target flips.
- 11 becomes 10 because the target flips.
Every input maps to a unique output, so the operation is reversible.
Example: If the control is 1 and the target is 0, CNOT changes 10 into 11. Applying CNOT again returns 11 to the original 10.

What is the Toffoli Gate Truth Table?
The Toffoli gate truth table covers all eight three-bit inputs. The first two bits are controls and the third is the target. Only rows where both controls are 1 flip the target.
| Control A | Control B | Target C | Output A | Output B | Output C |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 0 |
How to Read the Toffoli Truth Table
Group the rows by their first two bits, because the controls alone decide whether the target flips. Read that way, all eight rows follow four simple rules:
- The first two bits never change.
- Controls 00: the target remains unchanged.
- Controls 01 or 10: the target remains unchanged.
- Controls 11: the target flips from 0 to 1 or from 1 to 0.
If the target starts at 0, it ends up holding a โง b. The gate therefore performs reversible AND logic while keeping the control values intact.
Example: An input of 110 becomes 111 because both controls are 1. An input of 111 becomes 110 for the same reason.

How do CNOT and Toffoli Gates Work on Quantum States?
Because CNOT and Toffoli are quantum gates, their inputs can be superpositions. A superposition is a weighted combination of basis states.
Both gates act linearly, which means they apply their rule to every component of a superposition at once. This is how they create or change correlations between qubits.
How does CNOT Create Entanglement?
The classic quantum circuit example using CNOT creates a Bell state. This is a pair of qubits whose measurement results are perfectly correlated. It takes only two gates:
- Start with two qubits in the state |00โฉ.
- Apply a Hadamard gate to the first qubit, creating the superposition (|00โฉ + |10โฉ)/โ2.
- Apply CNOT with the first qubit as control and the second as target. The |10โฉ component becomes |11โฉ.
The result is:
(|00โฉ + |11โฉ)/โ2
This is an entangled Bell state. Neither qubit has a definite value of its own, yet measuring one tells you the other’s result.
CNOT does not entangle every input. On |10โฉ, it simply returns |11โฉ, which is not entangled, so the outcome depends on the initial state.
How does the Toffoli Gate Transform Quantum States?
Toffoli checks each computational-basis component of a three-qubit state. It flips the target in every component where both controls are 1. For example, (|000โฉ + |110โฉ)/โ2 becomes (|000โฉ + |111โฉ)/โ2.
This makes it useful inside larger circuits for arithmetic and reversible computation. However, it does not always create entanglement. On |110โฉ alone, it just outputs |111โฉ.
Key point: Truth tables describe each gate’s action on basis states, but quantum gates also transform superpositions of those states.
What are the Applications of CNOT and Toffoli Gates?
CNOT is a common building block for entanglement and controlled quantum operations. Toffoli is used for reversible Boolean logic and multi-qubit circuits. Their exact roles depend on the algorithm and on the hardware’s native operations.
Common Applications of the CNOT Gate
CNOT is the simplest way to make two qubits interact. Combined with single-qubit gates, it can build any quantum operation. That is why it appears in most practical circuits, including:
- Entanglement generation: Creating Bell states with suitable single-qubit gates.
- Quantum teleportation: Creating and then using a shared entangled pair.
- Quantum error correction: Encoding information and extracting error syndromes.
- Quantum algorithms: Implementing controlled interactions between qubits.
- Quantum circuit construction: Acting as the standard two-qubit gate in many circuit models.
Common Applications of the Toffoli Gate
Toffoli is the go-to gate for running classical logic on quantum data. Together with NOT, it is universal for reversible classical computation. Its main uses are:
- Reversible computing: Implementing logic while preserving the information needed to reverse it.
- Arithmetic circuits: Computing carry bits in reversible adders.
- Classical logic in quantum circuits: Implementing AND-related behavior while retaining the inputs.
- Quantum algorithms: Appearing in reversible logic constructions and some oracle implementations.
- Circuit synthesis: Being decomposed into smaller gates when hardware lacks a native Toffoli.
Can CNOT and Toffoli Be Used Together?
Yes. Quantum circuits routinely mix single-qubit and multi-qubit gates. CNOT creates correlations and helps build complex operations. Toffoli handles steps that need two control conditions.
A Toffoli can also be decomposed into gates from a suitable universal gate set, usually CNOTs plus single-qubit gates. The exact implementation and cost depend on the available hardware and gate set.
Key point: CNOT is widely used for two-qubit interactions, while Toffoli is especially useful when a circuit needs a reversible operation controlled by two qubits.
Are CNOT and Toffoli Gates Reversible?
Yes. Every computational-basis input of either gate maps to a unique output, so no information is lost. Applying either gate twice restores the original state, so each gate is its own inverse.
Why is Reversibility Important in Quantum Computing?
Ideal quantum gates are unitary operations, which can always be undone. That is why reversible gates never lose information about the input state.
Classical AND and OR squeeze two bits into one. An AND output of 0 could come from 00, 01 or 10, so the inputs cannot be recovered.
As a result, AND or OR cannot run as standalone unitary operations on the same input bits. Auxiliary (ancilla) qubits supply the extra workspace. A Toffoli writes a โง b onto an ancilla that starts at 0.
How do CNOT and Toffoli Undo Their Own Operations?
Each gate applies exactly the same test every time it runs, so a second application cancels the first one. The reasoning works identically for both gates:
- CNOT flips the target under the same control condition each time.
- Toffoli flips the target under the same two-control condition each time.
- Two identical applications therefore restore the original computational-basis state.
Because the gates act linearly, this holds for arbitrary quantum states too. Each gate is its own inverse.
Key point: Reversibility is central to quantum logic and explains why CNOT and Toffoli are valuable building blocks.
How do You Choose Between CNOT and Toffoli?
The choice depends on the control logic your circuit needs. Use CNOT when one control should flip a target. Use Toffoli when the target should flip only if two controls are both 1.
The decision table below matches common circuit requirements to the right gate:
| Requirement | Suitable gate | Reason |
|---|---|---|
| Flip a target based on one control | CNOT | Uses one control qubit |
| Flip a target only when two controls are 1 | Toffoli | Uses two control qubits |
| Create a Bell state from |00โฉ | Hadamard + CNOT | Creates the required superposition and correlation |
| Implement reversible AND-related logic | Toffoli | Computes the AND condition into a target bit using XOR |
| Build a larger controlled operation | Depends on the circuit | May require a combination of gates |
What should Beginners Learn First?
Quantum logic gates are easiest for beginners to learn by testing each rule yourself rather than memorizing it. Start with the simpler gate and follow this order:
- Learn the CNOT truth table and the control-target convention.
- Practise reading two-qubit circuit diagrams.
- Study how Hadamard plus CNOT creates entanglement.
- Move to Toffoli and its three-qubit truth table.
- Use a quantum circuit simulator to test basis-state inputs and compare outputs.
Once reversible logic feels natural, more complex quantum circuits become much easier to follow.
Conclusion
The key difference between CNOT and Toffoli gates lies in their control conditions. CNOT uses one control qubit to flip a target, while Toffoli uses two control qubits and flips the target only when both controls are 1. This makes CNOT useful for entanglement and two-qubit interactions, while Toffoli is especially valuable for reversible logic and quantum arithmetic.
For beginners, learning CNOT first and then progressing to Toffoli provides a strong foundation for understanding quantum circuits, reversible computation, and multi-qubit operations. By practising their truth tables, testing circuit diagrams, and experimenting with quantum simulators, you can develop a clearer understanding of how these gates work together in quantum algorithms.
Turn Your AI Knowledge into Practical Impact
Discover how AI can streamline workflows, strengthen data-driven decision-making, and improve operational efficiency with the Certificate Programme in AI-Powered Operations & Process Transformation by IIM Tiruchirappalli.
Explore the programme and learn how to apply AI to real-world operational challenges.
Frequently Asked Questions
How do you implement a CNOT gate in Qiskit?
Create a two-qubit circuit and call cx(control, target), as documented in IBM’s Qiskit reference for the CNOT (CXGate) gate. This example sets the control to 1 first, so the measurement returns 11:
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.x(0) # set the control qubit to 1
qc.cx(0, 1) # qubit 0 controls qubit 1
qc.measure_all()
How do you implement a Toffoli gate in a quantum circuit simulator?
Most simulators include a built-in Toffoli. Qiskit uses ccx(control1, control2, target), listed in IBM’s Qiskit reference for the Toffoli (CCXGate) gate. Cirq offers cirq.TOFFOLI.
To test it, set both controls to 1 with X gates, apply the gate and measure. Qiskit prints qubit 0 on the right, so an input of 110 displays as 011.
What is the difference between CNOT, CCNOT, and controlled-Z gates?
CNOT flips a target when one control is 1, and CCNOT (Toffoli) does so when two controls are 1. Controlled-Z flips no bits. Instead, it multiplies the |11โฉ component by โ1.
CZ is symmetric, so either qubit can act as its control. Placing Hadamard gates on the target before and after a CZ turns it into a CNOT.
How are CNOT and Toffoli gates represented in quantum circuit diagrams?
Each qubit is a horizontal wire read from left to right. Controls are solid dots (โ), and the target is a circled plus (โ). A vertical line joins them.
CNOT shows one control dot, while Toffoli shows two on the same line. An open circle (โ) marks a control that triggers on 0 instead of 1.
What is the matrix representation of a CNOT gate and a Toffoli gate?
With the control as the first qubit, CNOT is a 4ร4 identity matrix with its last two rows swapped. Toffoli is an 8ร8 identity matrix with the |110โฉ and |111โฉ rows swapped.
CNOT =
Qiskit orders qubits in reverse, so its printed matrices look rearranged even though the gates are identical.
How many elementary quantum gates are needed to implement a Toffoli gate?
The standard decomposition uses six CNOTs plus several single-qubit gates, such as Hadamard, T and Tโ . Shende and Markov proved that six CNOTs is the minimum without auxiliary qubits.
A simplified Toffoli that is correct only up to relative phases needs three CNOTs. Actual counts vary with each device’s native gate set.
Why are multi-qubit gates more challenging to implement on quantum hardware?
Multi-qubit gates require qubits to interact in a precisely controlled way while staying shielded from noise. That interaction is harder to calibrate than a single-qubit rotation.
Limited qubit connectivity can also add SWAP gates. Since a Toffoli usually runs as several two-qubit gates, it takes longer and has more chances for error.
How do CNOT and Toffoli gates support quantum error correction?
CNOTs spread one logical qubit across several physical qubits. They also copy parity information onto helper qubits, which reveals errors without measuring the protected data directly.
In the three-qubit bit-flip code, a Toffoli controlled by two syndrome qubits can flip the faulty qubit back. This avoids a mid-circuit measurement.
Can CNOT and Toffoli gates be used to build quantum arithmetic circuits?
Yes. A reversible half adder uses one Toffoli for the carry bit and one CNOT for the sum bit. Larger adders chain these steps across many qubits.
Efficient designs keep workspace small. The Cuccaro ripple-carry adder, for example, needs only one ancillary qubit.
What is the role of auxiliary qubits when implementing reversible logic gates?
Auxiliary qubits are workspace qubits that usually start at |0โฉ. They hold intermediate results, such as an AND computed by a Toffoli, without overwriting the inputs.
Afterward, the circuit reverses those gates to reset them to |0โฉ. This step is called uncomputation, and it stops leftover data from disturbing the rest of the computation.
How does gate fidelity affect the performance of CNOT and Toffoli operations?
Gate fidelity measures how closely a real gate matches its ideal operation. Errors build up with every gate, so a decomposed Toffoli usually performs worse than a single CNOT.
On many current platforms, two-qubit gates are among the noisiest operations. That is why reducing CNOT counts is a common goal in circuit optimization.
What beginner quantum circuit projects can help practise CNOT and Toffoli gates?
These projects need only a few qubits and run on any free simulator. Each one tests a different property, so check every output against the truth tables above:
- Build a Bell state with Hadamard and CNOT, then measure the correlations.
- Extend it to a three-qubit GHZ state using two CNOTs.
- Confirm each gate is self-inverse by applying it twice.
- Build a reversible half adder from one Toffoli and one CNOT.
- Simulate the three-qubit bit-flip code.
Sources
- On the CNOT-Cost of Toffoli Gates – Vivek V. Shende and Igor L. Markov
- Elementary Gates for Quantum Computation – Barenco et al.
- Reversible Computation and the Toffoli Gate – Peter Shor’s MIT lecture notes
- CXGate (CNOT) API Reference – IBM Qiskit Documentation
- CCXGate (Toffoli) API Reference – IBM Qiskit Documentation






