The surface code is unarguably the leading quantum error correction code for 2-D nearest neighbor architectures, featuring a high threshold error rate of approximately 1%, low overhead implementations of the entire Clifford group, and flexible, arbitrarily long-range logical gates. These highly desirable features come at the cost of significant classical processing complexity. We show how to perform the processing associated with an n × n lattice of qubits, each being manipulated in a realistic, fault-tolerant manner, in O(n 2 ) average time per round of error correction. We also describe how to parallelize the algorithm to achieve O(1) average processing per round, using only constant computing resources per unit area and local communication. Both of these complexities are optimal.Quantum computing promises exponentially faster processing of certain problems, including factoring [1] and simulating quantum physics [2]. Many quantum algorithms are now known [3]. The primary challenges are to mitigate and cope with the imperfections of quantum devices. The surface code [4,5] supports a powerful quantum computing scheme [6][7][8] featuring an experimentally realistic threshold error rate of approximately 1% [9] and requiring only a 2-D square lattice of qubits with nearest neighbor interactions. In this work, we describe how to perform the complex classical processing associated with the full, fault-tolerant scheme in a complexity-optimal manner. Using the current version of our code, we can simulate the fault-tolerant operation of millions of qubits, four orders of magnitude more than in any previous work.