QuantumSimulator
Interactive Course
Interactive chapters from intuition to mastery
Structured Lessons
Eight modules with formulas and self-checks
Quantum Brain
Navigate lessons, laws, gates, devices, and tools
Guided Experiments
Hands-on circuits that teach one idea each
Circuit Lab
Build circuits, run them, and see the results
Gate Reference
Quick reference for all quantum gates
Cryostat Studio
3D cryostat design and simulation
Component Catalog
Browse all cryostat components
System Checks
Check your design for errors
Menu
physics
Interactive Course
Interactive chapters from intuition to mastery
Structured Lessons
Eight modules with formulas and self-checks
Quantum Brain
Navigate lessons, laws, gates, devices, and tools
Guided Experiments
Hands-on circuits that teach one idea each
simulator
Circuit Lab
Build circuits, run them, and see the results
Gate Reference
Quick reference for all quantum gates
wiringStudio
Cryostat Studio
3D cryostat design and simulation
Component Catalog
Browse all cryostat components
System Checks
Check your design for errors
Home/Quantum Physics/Lessons/SWAP Gate
SW

SWAP Gate

Multi-qubit2-qubitswap

Exchanges the complete quantum states of two qubits.

Intuition

The SWAP gate exchanges the full quantum state of two qubits. If qubit A is in state ∣ψ⟩ and qubit B is in state ∣ϕ⟩, after SWAP, qubit A holds ∣ϕ⟩ and qubit B holds ∣ψ⟩. This transfer includes all amplitudes, phases, and entanglement relationships. SWAP is especially important on real hardware where not every pair of qubits can interact directly. When you need two distant qubits to interact, you SWAP one of them closer first.

Matrix representation
​1000​0010​0100​0001​​
Action on states
∣ab⟩→∣ba⟩
Circuit
q0q1XSW
Full technical statement

SWAP exchanges the computational basis states of two qubits: ∣ab⟩ becomes ∣ba⟩ for all values of a and b. It can be built from three CNOT gates: CNOT(1,2) then CNOT(2,1) then CNOT(1,2). SWAP preserves entanglement structure. It does not create or destroy correlations. It simply relabels which physical qubit holds which logical state. The gate is symmetric (swapping the qubit labels gives the same gate) and is its own inverse (SWAP² = I).

What changes in measurements

The measurement outcomes of the two qubits trade places in the output distribution.

Bloch sphere

Exchanges the Bloch vectors of the two qubits. Each qubit ends up with the other’s full state, including phase and purity.

Truth table
|00⟩→|00⟩
|01⟩→|10⟩
|10⟩→|01⟩
|11⟩→|11⟩
Step-by-step example

Routing qubits on limited hardware

  1. 1Qubit 0 is in ∣1⟩ and qubit 1 is in ∣0⟩. The joint state is ∣10⟩.
  2. 2Apply SWAP. The state becomes ∣01⟩.
  3. 3Qubit 0 now holds ∣0⟩ and qubit 1 holds ∣1⟩. They have traded places.
  4. 4This works the same way on superpositions: SWAP(α∣00⟩+β∣10⟩=α∣00⟩+β∣01⟩.
Where this gate appears
  • Moving quantum states to adjacent positions on hardware with limited connectivity
  • Implementing circuits that require non-adjacent qubit interactions
  • Quantum sorting networks
  • Building the Fredkin gate (controlled-SWAP) for reversible computation
Connected gates
  • SWAP = three CNOTs in sequence, using either qubit ordering convention
  • SWAP² = I — swapping twice returns both qubits to their original positions
  • √SWAP (the square root of SWAP) is an entangling gate used in some universal gate sets
  • Fredkin = controlled-SWAP, a three-qubit gate useful in reversible computation
Tempting but wrong

It is tempting to think SWAP is trivially classical since it just moves data around. That sounds right because the truth table matches classical bit exchange. What actually happens is that SWAP transfers the full quantum state, including superposition and phase information, perfectly intact. Doing this without disturbing the quantum information is non-trivial in practice.

Why this gate matters for what comes next

Real quantum hardware has limited connectivity between qubits. SWAP gates are the mechanism for moving quantum information to where it needs to be. Minimizing SWAP overhead is one of the major challenges in compiling quantum circuits for real devices.

Test your understanding

Does applying SWAP to two qubits create entanglement?

Quick reference →↗ Nielsen and Chuang, Quantum Computation and Quantum Information
←
Previous
Toffoli
Next
Phase
→
← Back to all lessons