The hippocampus is thought to guide navigation by forming a cognitive map of space. Different environments differ in geometry and the availability of cues that can be used for navigation. Although several spatial coding mechanisms are known to coexist in the hippocampus, how they are influenced by various environmental features is not well understood. To address this issue, we examined the spatial coding characteristics of hippocampal neurons in mice and rats navigating in different environments. We found that CA1 place cells located in the superficial sublayer were more active in cue-poor environments and preferentially used a firing rate code driven by intra-hippocampal inputs. In contrast, place cells located in the deep sublayer were more active in cue-rich environments and used a phase code driven by entorhinal inputs. Switching between these two spatial coding modes was supported by the interaction between excitatory gamma inputs and local inhibition.