Quantum computers hold the promise of solving computational problems which are intractable using conventional methods [1]. For fault-tolerant operation quantum computers must correct errors occurring due to unavoidable decoherence and limited control accuracy [2]. Here, we demonstrate quantum error correction using the surface code, which is known for its exceptionally high tolerance to errors [3][4][5][6]. Using 17 physical qubits in a superconducting circuit we encode quantum information in a distance-three logical qubit building up on recent distance-two error detection experiments [7][8][9]. In an error correction cycle taking only 1.1 µs, we demonstrate the preservation of four cardinal states of the logical qubit. Repeatedly executing the cycle, we measure and decode both bit-and phase-flip error syndromes using a minimum-weight perfect-matching algorithm in an error-modelfree approach and apply corrections in postprocessing. We find a low error probability of 3 % per cycle when rejecting experimental runs in which leakage is detected. The measured characteristics of our device agree well with a numerical model. Our demonstration of repeated, fast and highperformance quantum error correction cycles, together with recent advances in ion traps [10], support our understanding that fault-tolerant quantum computation will be practically realizable.