The hippocampal formation contains neurons responsive to an animal's current location and orientation, which together provide the organism with a neural map of space.1,2,3 Spatially tuned neurons rely on external landmark cues and internally generated movement information to estimate position.4,5 An important class of landmark cue are the boundaries delimiting an environment, which can define place cell field position6,7 and stabilize grid cell firing.8 However, the precise nature of the sensory information used to detect boundaries remains unknown. We used 2-dimensional virtual reality (VR)9 to show that visual cues from elevated walls surrounding the environment are both sufficient and necessary to stabilize place and grid cell responses in VR, when only visual and self-motion cues are available. By contrast, flat boundaries formed by the edges of a textured floor did not stabilize place and grid cells, indicating only specific forms of visual boundary stabilize hippocampal spatial firing. Unstable grid cells retain internally coherent, hexagonally arranged firing fields, but these fields "drift" with respect to the virtual environment over periods >5 s. Optic flow from a virtual floor does not slow drift dynamics, emphasizing the importance of boundary-related visual information. Surprisingly, place fields are more stable close to boundaries even with floor and wall cues removed, suggesting invisible boundaries are inferred using the motion of a discrete, separate cue (a beacon signaling reward location). Subsets of place cells show allocentric directional tuning toward the beacon, with strength of tuning correlating with place field stability when boundaries are removed.