The medial entorhinal cortex (MEC) is part of a neural system for mapping a subject’s position within a physical environment 1,2 . Grid cells, a key component of this system, fire in a characteristic hexagonal pattern of locations 3 , and are organized in modules 4,5 which collectively form a population code for the animal’s allocentric position 1,6–8 . The invariance of the correlation structure of this population code across environments 9,10 and behavioural states 11,12 , independently of specific sensory inputs, has pointed to intrinsic, recurrently connected continuous attractor networks (CANs) as a possible substrate of the grid pattern 1,2,13–16 . However, whether grid cell networks show continuous attractor dynamics, and how they interface with inputs from the environment, has remained elusive due to the small samples of cells obtained to date. Here we show, with simultaneous recordings from many hundreds of grid cells, and subsequent topological data analysis, that the joint activity of grid cells from an individual module resides on a toroidal manifold, as expected in a two-dimensional CAN. Positions on the torus correspond to the moving animal’s position in the environment. Individual cells are preferentially active at singular positions on the torus. Their positions are maintained, with minimal distortion, between environments and from wakefulness to sleep, as predicted by CAN models for grid cells but not by alternative feed-forward models where grid patterns are created from external inputs by Hebbian plasticity 17–22 . This demonstration of network dynamics on a toroidal manifold provides the first population-level visualization of CAN dynamics in grid cells.