# CCZ gate **CCZ gate** (doubly-controlled Z) is a three-qubit gate that applies a [[z-gate|Pauli Z]] to the target qubit if and only if both control qubits are $\lvert 1\rangle$, and does nothing otherwise. Because Z acts as a phase flip, the CCZ gate is fully symmetric: any permutation of the three qubits produces the same unitary. The gate maps $\lvert a, b, c\rangle \mapsto (-1)^{a \wedge b \wedge c}\lvert a, b, c\rangle$, flipping the sign of $\lvert 111\rangle$ and leaving all other computational basis states unchanged. Its matrix is the $8 \times 8$ identity with the bottom-right entry negated (basis ordered $\lvert 000\rangle$ through $\lvert 111\rangle$): $$\text{CCZ} = \begin{pmatrix} 1&0&0&0&0&0&0&0\\ 0&1&0&0&0&0&0&0\\ 0&0&1&0&0&0&0&0\\ 0&0&0&1&0&0&0&0\\ 0&0&0&0&1&0&0&0\\ 0&0&0&0&0&1&0&0\\ 0&0&0&0&0&0&1&0\\ 0&0&0&0&0&0&0&-1 \end{pmatrix}$$ ## Relation to CCX CCZ and [[ccx-gate|CCX]] are locally equivalent: applying a Hadamard to the target qubit before and after a CCX gives CCZ, and vice versa. The identity is $\text{CCZ} = (I \otimes I \otimes H) \cdot \text{CCX} \cdot (I \otimes I \otimes H)$. In practice, most frameworks implement CCZ by wrapping CCX with Hadamard layers rather than providing a separate decomposition. ## Properties The CCZ gate is its own inverse: $\text{CCZ}^2 = I$. Its three-qubit symmetry means that, unlike [[cx-gate|CX]] and [[ccx-gate|CCX]], there is no notion of a designated target — every qubit plays an equal role. CCZ appears in quantum phase-kickback constructions, Grover oracle implementations, and as a building block in fault-tolerant gate sets where the T-count of its decomposition (six T gates, same as CCX) is the relevant cost metric. ## List of code implementations - [[ccz-gate-qiskit|CCZ gate (Qiskit)]]