SWAP Gate

Exchanges the states of two qubits.


The SWAP gate does exactly what its name suggests: it swaps the quantum states of two qubits.

Definition

Action:

InputOutput

Circuit Symbol

──✕──
  │
──✕──

Or sometimes with crossing lines.

Decomposition

SWAP can be built from three CNOTs:

──●────⊕────●──
  │    │    │
──⊕────●────⊕──

This is the standard decomposition used when SWAP isn’t a native gate.

Variants

√SWAP (Square Root of SWAP)

An entangling gate sometimes native to certain hardware.

iSWAP

Swaps states and adds a phase. Native gate on some superconducting processors (Google Sycamore).

CSWAP (Fredkin Gate)

Controlled-SWAP: swaps two qubits only when control is .

Why It Matters

Connectivity

Many quantum computers have limited qubit connectivity (not all pairs can interact directly). SWAP gates route quantum information:

Before: q0 ─ q1 ─ q2 ─ q3  (linear connectivity)

To interact q0 with q3:
1. SWAP q0, q1
2. SWAP q1, q2
3. Now original q0 state is next to q3

Circuit Compilation

Mapping logical circuits to physical hardware often requires inserting many SWAP gates, increasing circuit depth and errors.

SWAP Test

A circuit for estimating state overlap:

|0⟩ ──H──●──H──M
         │
|ψ⟩ ─────✕─────
         │
|φ⟩ ─────✕─────

Probability of measuring 0 is .


See also: CNOT Gate, Quantum Gate, Circuit Depth