Animals can use different strategies to navigate. They may guide their movements by relying on external cues in their environment or, alternatively, by using an internal cognitive map of the space around them and their position within it. An essential part of this representation are heading cells, neurons whose activity depends on the heading direction of the animal. Although those cells have been found in vertebrates, the full network has never been observed and there is very little mechanistic understanding of how these cells acquire their response properties. In this study, we use volumetric functional imaging in larval zebrafish to observe, for the first time in a vertebrate, a full network that encodes allocentric heading direction. This network of approximately one hundred inhibitory neurons is arranged in an anatomical circle in the anterior hindbrain. Its activity is driven purely by the integration of internally generated signals, indicating that a simple vertebrate brain can encode maps of how an animal moves within its surroundings. Single cell reconstructions of electron micrographs allow us to uncover how the connectivity pattern of neurons within the network supports the implementation of a ring attractor network. The neurons we identify share features with neurons in the dorsal tegmentum nucleus of rodents and the fly central complex, showing that similar connectivity and mechanistic principles underlie the generation of cognitive maps of heading direction across the animal kingdom.