SWAP gate

Exchanges the states of two qubits.

Permutation · 2 qubits · reviewed November 2026

Matrix

[ 1 0 0 0 ]
[ 0 0 1 0 ]
[ 0 1 0 0 ]
[ 0 0 0 1 ]

What it does

|01⟩→|10⟩
|10⟩→|01⟩

In plain words

SWAP is built from three CNOTs. On hardware where only some pairs of qubits can interact, compilers insert SWAPs to bring distant qubits together, and each one costs three two-qubit gates.

Identities

  • SWAP = CX(0,1)·CX(1,0)·CX(0,1)
  • SWAP·SWAP = I

Where it is used

  • Routing on limited connectivity
  • Reordering outputs of the QFT

Code

# Qiskit
qc.swap(0, 1)

// OpenQASM 2.0
swap q[0],q[1];

Qiskit prints qubit 0 on the right of a bitstring. The builder prints it on the left.

See it in an example

Related gates

Questions

Does SWAP create entanglement?

No. It only exchanges two qubits, so a product state stays a product state.

Try the SWAP gate in the Circuit Builder →