Quantum Lab
Quantum Lab

An interactive quantum mechanics learning platform and cryostat wiring co-design tool. From plain-language intuition to formal mathematics.

contact@quantumcircuitsimulator.com

Product

  • Circuit Lab
  • Learn
  • Hardware Studio
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Quantum Lab. All rights reserved.

This site, including its original quantum simulations, cryostat reference systems, 3D models, and interface design, contains protected proprietary material.

Home/Quantum Physics/Lessons/SWAP Gate
SW

SWAP Gate

Multi-qubit2-qubitswap

Exchanges the quantum states of two qubits.

Intuition

The SWAP gate does exactly what its name says: it exchanges the complete quantum states 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 includes all amplitudes, phases, and entanglement relationships. SWAP is especially important in hardware where not all qubits can interact directly — you need to move quantum states around to bring them next to each other.

Matrix representation
​1000​0010​0100​0001​​
Action on states
∣ab⟩→∣ba⟩
Circuit
q0q1XSW
Precise explanation

SWAP exchanges the computational basis states of two qubits: |ab⟩ → |ba⟩. It can be decomposed into three CNOT gates: CNOT(1,2)·CNOT(2,1)·CNOT(1,2). SWAP preserves entanglement structure — it simply relabels which physical qubit holds which logical state. The gate is symmetric and its own inverse (SWAP² = I).

Observable effect

Qubit roles swap in the output distribution.

Bloch sphere

Exchanges the Bloch vectors of 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⟩
Worked example

Routing qubits on limited hardware

  1. 1Suppose qubit 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 identically on superpositions: SWAP(α|00⟩ + β|10⟩) = α|00⟩ + β|01⟩.
Common use cases
  • Routing states on hardware with limited qubit connectivity
  • Implementing quantum circuits that need non-adjacent qubit interactions
  • Quantum sorting networks
  • Building the Fredkin gate (controlled-SWAP)
Relation to other gates
  • SWAP = three CNOTs (any ordering convention)
  • SWAP² = I — swapping twice returns to the original state
  • √SWAP is an entangling gate used in some universal gate sets
  • Fredkin = controlled-SWAP, useful in reversible computation
Common misconception

SWAP might seem trivially classical, but it matters because it preserves quantum information perfectly — amplitudes, phases, and entanglement all transfer intact.

Why this gate matters

Real quantum hardware has limited connectivity between qubits. SWAP gates are how you move quantum information to where it needs to be. Minimizing SWAP overhead is a major challenge in quantum circuit compilation.

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