First time studying this topic?

Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.

Topic 6.9

The CNOT Gate: Entanglement & The XOR Truth Table

Master the crown jewel of two-qubit gates: the Controlled-NOT (CNOT) gate, parity flips, and synthesizing Bell states.

Learning Objectives

  • βœ“Define the 4x4 CNOT matrix and its Boolean truth table
  • βœ“Demonstrate the parity action: |c, t> -> |c, c XOR t>
  • βœ“Understand why CNOT + single-qubit rotations forms a Universal Quantum Computer

πŸ“–Let's Begin with a Story

In 1995, Spanish theoretical physicists Ignacio Cirac and Peter Zoller were sitting in an Austrian coffee house scribbling on napkins. They were trying to figure out how to build the first physical two-qubit quantum gate using laser beams and cold ions trapped in an electromagnetic vacuum. The gate they chose to build was the Controlled-NOT (CNOT) gate. Why CNOT? Because mathematicians had just proven a theorem of monumental importance: If you have single-qubit rotations (Hadamard, Phase) AND a CNOT gate, you have a Universal Quantum Computer! You can construct ANY quantum algorithm, simulate ANY molecule, and crack ANY encryption code using nothing more than single-qubit rotations and CNOT gates. CNOT is the universal glue of quantum computing.

Why Should You Learn The CNOT Gate: Entanglement & The XOR Truth Table?

🎯 Practical & Engineering Stakes

The universal entangler

CNOT is the primary multi-qubit gate supported by IBM, Google, and IonQ hardware. Understanding its truth table, matrix structure, and phase properties is essential for every quantum circuit you will ever design.

What Is It?

Simple Explanation

The CNOT Gate (Controlled-NOT): - Control Qubit (Top): The Boss. It never changes! - Target Qubit (Bottom): The Worker. The Rule: - If Control is 0 -> Target stays unchanged. - If Control is 1 -> Target FLIPS (0 becomes 1, 1 becomes 0)! In binary math, it computes the XOR sum: ∣c,tβŸ©β†’βˆ£c,cβŠ•t⟩|c, t\rangle \rightarrow |c, c \oplus t\rangle.

Technical Explanation

The Controlled-NOT gate CX∈U(4)CX \in U(4) is a linear operator whose computational action is: CX∣c,t⟩=∣c,cβŠ•t⟩CX |c, t\rangle = |c, c \oplus t\rangle where βŠ•\oplus denotes addition modulo 2 (exclusive OR). In matrix form: CX=(1000010000010010)CX = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix} Together with single-qubit unitary operations U(2)U(2), the set {CX,U(2)}\{CX, U(2)\} forms a universal gate library capable of exact synthesis of any element in U(2n)U(2^n) via the Barenco et al. (1995) construction.

πŸ“š Key Terms

CNOT (Controlled-X)

Simple: Flips the target qubit if and only if the control qubit is 1.
Technical: Two-qubit unitary operator mapping basis state ∣c,t⟩|c, t\rangle to ∣c,cβŠ•t⟩|c, c \oplus t\rangle.

XOR (Exclusive OR)

Simple: Outputs 1 if inputs are different; outputs 0 if inputs are the same.
Technical: Addition modulo 2 in Galois field F2\mathbb{F}_2.

Universal Gate Library

Simple: A small set of gates that can build any possible quantum computer circuit.
Technical: A collection of gates whose generated subgroup is dense in SU(2n)SU(2^n).

Q-Sphere Lab: The CNOT Gate: Entanglement & The XOR Truth Table

IBM Q-Sphere Model

Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 6.9

Azimuth: 45Β°Elevation: 25Β°
+Z |0⟩-Z |1⟩+X |+⟩+Y |+i⟩01|ψ⟩
Q-Sphere Phase Color:
0 Ο€/2 Ο€ 3Ο€/2

Quantum Statevector

dim(H) = 2
|ψ⟩ = (1.000 + 0.000i)|0⟩
     + (0.000 + 0.000i)|1⟩
Polar Angle (ΞΈ):0.0Β° (0.000Ο€ rad)
Phase Angle (Ο•):0.0Β° (0.000Ο€ rad)

Born Rule Probabilities: P(x) = |⟨x|ψ⟩|²Σ P = 1.00

P(|0⟩) = |α|²100.0%
P(|1⟩) = |β|²0.0%
Quantum Measurement

Apply Single-Qubit Unitary Gates

Presets:
Continuous Polar Angle θ (0° = |0⟩, 180° = |1⟩):0.0°
Continuous Phase Angle Ο• (0Β° to 360Β°):0.0Β°
Recent Operations Log:
#1Initial state: |0⟩

πŸ“ Mathematical Foundation

LaTeX KaTeX
CX∣c,t⟩=∣c,cβŠ•t⟩,CX=(1000010000010010)CX |c, t\rangle = |c, c \oplus t\rangle, \quad CX = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}

What does it mean?

The Controlled-NOT (CNOT / CX) Gate: The bedrock of quantum computing and entanglement. If control qubit c = 0, target qubit t stays the same (0 βŠ• t = t). If control c = 1, target qubit t flips (1 βŠ• t = NOT t). Applying CNOT when the control qubit is in superposition creates the famous entangled Bell state!

Understanding the Symbols

Symbol / TermMeaningBeginner Interpretation
ccControl qubit bit (0 or 1)Remains unchanged after the gate
ttTarget qubit bit (0 or 1)Flips if and only if c = 1
cβŠ•tc \oplus tBitwise XOR (addition modulo 2)Classical XOR truth table: 0βŠ•0=00\oplus 0=0, 0βŠ•1=10\oplus 1=1, 1βŠ•0=11\oplus 0=1, 1βŠ•1=01\oplus 1=0
CXCX4Γ—4 CNOT permutation matrixSwaps basis states ∣10βŸ©β†”βˆ£11⟩|10\rangle \leftrightarrow |11\rangle while leaving ∣00⟩|00\rangle and ∣01⟩|01\rangle fixed

πŸ“Š Numerical Example

Creating the entangled Bell state |Ξ¦+⟩ using Hadamard on qubit 0, followed by CNOT(0 β†’ 1):

Initial State: ∣00⟩|00\rangle = [1, 0, 0, 0]^T Step 1: Apply H to Qubit 0 (H βŠ— I): (H βŠ— I) ∣00⟩|00\rangle = [(∣0⟩|0\rangle + ∣1⟩|1\rangle)/√2] βŠ— ∣0⟩|0\rangle = (∣00⟩|00\rangle + ∣10⟩|10\rangle)/√2 = [1/√2, 0, 1/√2, 0]^T Step 2: Apply CNOT (CX): CX Γ— [1/√2, 0, 1/√2, 0]^T Row 1: 1Γ—(1/√2) = 1/√2 (∣00⟩|00\rangle) Row 2: 0 (∣01⟩|01\rangle) Row 3: 0 (∣10⟩|10\rangle) Row 4: 1Γ—(1/√2) = 1/√2 (∣11⟩|11\rangle) Result: [1/√2, 0, 0, 1/√2]^T = (∣00⟩|00\rangle + ∣11⟩|11\rangle)/√2 = ∣Φ+⟩|\Phi+\rangle

Result: The two qubits are now maximally entangled: measuring one instantly determines the other with 100% correlation.

βš™οΈ How Does It Work?

1

|00> -> |00>

Control is 0; target 0 stays 0.

2

|01> -> |01>

Control is 0; target 1 stays 1.

3

|10> -> |11>

Control is 1; target 0 flips to 1.

4

|11> -> |10>

Control is 1; target 1 flips to 0.

🌍 Where Is It Used?

Bell State Generation

Problem: Creating maximally entangled pairs for quantum communications.

Solution: Hadamard on qubit 0 followed by CNOT(0, 1) creates canonical Bell pair (|00> + |11>)/sqrt(2).

Quantum Parity Checking

Problem: Measuring whether two qubits are identical or different without measuring their individual values.

Solution: CNOT targets an ancilla qubit, recording parity c1 XOR c2.

🎯 Try It Yourself

If the input to a CNOT gate is |11>, what is the output state?

Interactive activity component

🐍 Python Hands-On: Synthesizing and Simulating an Entangled Bell State with CNOT in Qiskit

Construct a 2-qubit circuit with Hadamard and CNOT gates to create the canonical Bell state (|00> + |11>)/sqrt(2), execute on the Aer simulator, and analyze correlated counts.

Open Colab

1Install Required Packages

For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:

Terminal / Notebook Install Commandbash
!pip install qiskit qiskit-aer matplotlib
Packages:
qiskitqiskit-aermatplotlib

2Import Libraries

Import Statementspython
1from qiskit import QuantumCircuit
2from qiskit_aer import Aer
3from qiskit.visualization import plot_histogram
4import matplotlib.pyplot as plt

from qiskit import QuantumCircuit β†’ Circuit constructor

from qiskit_aer import Aer β†’ Qiskit Aer simulator provider

from qiskit.visualization import plot_histogram β†’ Histogram plotting utility

import matplotlib.pyplot as plt β†’ Matplotlib renderer

3Demonstration Code & Logic

Python Execution Codepython
1# Create a Quantum Circuit with 2 Qubits and 2 Classical Bits
2qc = QuantumCircuit(2, 2)
3
4# Apply Hadamard gate to the first qubit (creates superposition)
5qc.h(0)
6
7# Apply CNOT gate (entangles qubit 0 and qubit 1)
8qc.cx(0, 1)
9
10# Measure both qubits into respective classical bits
11qc.measure([0, 1], [0, 1])
12
13# Use Qiskit's Aer simulator
14simulator = Aer.get_backend('aer_simulator')
15
16# Run the circuit for 1,024 shots
17job = simulator.run(qc, shots=1024)
18result = job.result()
19counts = result.get_counts()
20
21# Print results
22print("Measurement Results (Counts):", counts)
23
24# Plot results histogram
25plot_histogram(counts)
26plt.show()
Step-by-Step Code Breakdown:

# Create a Quantum Circuit with 2 Qubits and 2 Classical Bits

Circuit creation

qc = QuantumCircuit(2, 2)

2 qubits, 2 classical bits

# Apply Hadamard gate to the first qubit (creates superposition)

Superposition step

qc.h(0)

H gate on q0: (|0> + |1>)/sqrt(2)

# Apply CNOT gate (entangles qubit 0 and qubit 1)

Entanglement step

qc.cx(0, 1)

CNOT: q0 controls q1, generating Bell state (|00> + |11>)/sqrt(2)

# Measure both qubits into respective classical bits

Measurement

qc.measure([0, 1], [0, 1])

Collapse both qubits simultaneously

# Use Qiskit's Aer simulator

Simulator setup

simulator = Aer.get_backend('aer_simulator')

Instantiate Aer backend

# Run the circuit for 1,024 shots

Execution

job = simulator.run(qc, shots=1024)

Simulate 1024 trials

result = job.result()

Extract result object

counts = result.get_counts()

Extract dictionary of outcome counts

# Print results

Console output

print("Measurement Results (Counts):", counts)

Display bitstring frequencies

# Plot results histogram

Visualization

plot_histogram(counts)

Render histogram bar chart

plt.show()

Show matplotlib plot

πŸ“‹ Complete Script (All-in-One)

Click "Copy for Colab", open Google Colab, paste into a single cell, and run.

Google Colab Notebook Scriptpython
1# =========================================================
2# Synthesizing and Simulating an Entangled Bell State with CNOT in Qiskit
3# Prepared for Google Colab (Run with Shift + Enter)
4# =========================================================
5
6# Step 1: Install required packages
7!pip install qiskit qiskit-aer matplotlib
8
9# Step 2: Import libraries
10from qiskit import QuantumCircuit
11from qiskit_aer import Aer
12from qiskit.visualization import plot_histogram
13import matplotlib.pyplot as plt
14
15# Step 3: Run Demonstration
16# Create a Quantum Circuit with 2 Qubits and 2 Classical Bits
17qc = QuantumCircuit(2, 2)
18
19# Apply Hadamard gate to the first qubit (creates superposition)
20qc.h(0)
21
22# Apply CNOT gate (entangles qubit 0 and qubit 1)
23qc.cx(0, 1)
24
25# Measure both qubits into respective classical bits
26qc.measure([0, 1], [0, 1])
27
28# Use Qiskit's Aer simulator
29simulator = Aer.get_backend('aer_simulator')
30
31# Run the circuit for 1,024 shots
32job = simulator.run(qc, shots=1024)
33result = job.result()
34counts = result.get_counts()
35
36# Print results
37print("Measurement Results (Counts):", counts)
38
39# Plot results histogram
40plot_histogram(counts)
41plt.show()
⚑ How to Run in Google Colab (3 Quick Steps)
  1. Click "Copy for Google Colab" above.
  2. Click Open New Google Colab Notebook (opens in a new tab).
  3. Click on the first empty code cell, press Ctrl + V (or Cmd + V) to paste, then press Shift + Enter to execute!

πŸ”„ Algorithmic Execution Flow

1
Superposition Seed

Hadamard gate on qubit 0 creates an equal superposition of |0> and |1>.

β†’
2
Entangling CNOT

Controlled-NOT gate flips qubit 1 only when qubit 0 is |1>, creating the entangled Bell state (|00> + |11>)/sqrt(2).

β†’
3
Aer Measurement Collapse

Simulator records 1,024 shots. The qubits always collapse in perfect lockstep: ~50% '00' and ~50% '11', with 0% chance of '01' or '10'.

πŸ“₯ Input / Initial State
2-qubit circuit with H(0), CX(0, 1), and 1,024 simulator shots
πŸ“€ Expected Output
Measurement Results (Counts): {'00': 514, '11': 510}
πŸ’‘ What Does This Demonstration Show?

The CNOT gate acts as the universal entangler. Measuring qubit 0 instantly reveals the state of qubit 1 with 100% correlation, experimentally confirming quantum entanglement.

Course Learning Resource β€’ Slide DeckLesson 810 Slides

Lesson 8: Two Qubits and Entanglement

Hadamard, CNOT gate, Bell state synthesis, Aer simulation, and correlated measurement histograms.

Author: Dr. Syed Muzamil Bashaβ€’ FDP Approved Curriculum
Open in New Tab

πŸ“ Learning Check

Test your understanding with these questions. Remember, this is for learning, not examination!

Question 1: Why is the CNOT gate called reversible when classical XOR gates are irreversible?

Question 2: What operation does the CNOT gate perform?

Question 3: What is the matrix representation of CNOT (control on qubit 0, target on qubit 1)?

Question 4: How do you create a Bell state |Φ⁺⟩ = (|00⟩ + |11⟩)/√2 from |00⟩?

Question 5: What makes CNOT special compared to single-qubit gates?