Engineering desired operations on qubits subjected to the deleterious effects of their environment is a critical task in quantum information processing, quantum simulation and sensing. The most common approach is to rely on open-loop quantum control techniques, including optimal control algorithms, based on analytical [1] or numerical [2] solutions, Lyapunov design [3] and Hamiltonian engineering [4]. An alternative strategy, inspired by the success of classical control, is feedback control [5]. Because of the complications introduced by quantum measurement [6], closed-loop control is less pervasive in the quantum settings and, with exceptions [7,8], its experimental implementations have been mainly limited to quantum optics experiments. Here we implement a feedback control algorithm with a solid-state spin qubit system associated with the Nitrogen Vacancy (NV) centre in diamond, using coherent feedback [9] to overcome limitations of measurement-based feedback, and show that it can protect the qubit against intrinsic dephasing noise for milliseconds. In coherent feedback, the quantum system is connected to an auxiliary quantum controller (ancilla) that acquires information about the system's output state (by an entangling operation) and performs an appropriate feedback action (by a conditional gate). In contrast to open-loop dynamical decoupling (DD) techniques [10], feedback control can protect the qubit even against Markovian noise and for an arbitrary period of time (limited only by the ancilla coherence time), while allowing gate operations. It is thus more closely related to Quantum Error Correction schemes [11][12][13][14], which however require larger and increasing qubit overheads. Increasing the number of fresh ancillas allows protection even beyond their coherence time. We can further evaluate the robustness of the feedback protocol, which could be applied to quantum computation and sensing, by exploring an interesting tradeoff between information gain and decoherence protection, as measurement of the ancilla-qubit correlation after the feedback algorithm voids the protection, even if the rest of the dynamics is unchanged.To demonstrate coherent feedback with spin qubits, we choose two of the most common tasks for qubits, implementing the no-operation (NOOP) and NOT gates, while cancelling the effects of noise. A simple, measurementbased feedback scheme, exploiting one ancillary qubit, was proposed in [16]. The correction protocol (Fig. 1a) works by entangling the qubit-ancilla system before the desired gate operation. By selecting an entangling operation U c appropriate for the type of bath acting on the system, information about the noise action is encoded in the ancilla state. After undoing the entangling operation, the qubit coherence can be restored by a feedback action, Hadamard gates prepare and read out a superposition state of the qubit, |φ q = 1 √ 2 (|0 + |1 ). Amid entangling gates between qubit and ancilla, the qubit is subjected to noise (and possibly unitary gates U ). We assume the ancil...