The hippocampus contains neural representations capable of supporting declarative memory. Hippocampal place cells are one such representation, firing in one or few locations in a given environment. Between environments, place cell firing fields remap (turning on/off or moving to a new location) to provide a population-wide code for distinct contexts. However, the manner by which contextual features combine to drive hippocampal remapping remains a matter of debate. Using large-scale in vivo two-photon intracellular calcium recordings in mice during virtual navigation, we show that remapping in the hippocampal region CA1 is driven by prior experience regarding the frequency of certain contexts and that remapping approximates an optimal estimate of the identity of the current context. A simple associative-learning mechanism reproduces these results. Together, our findings demonstrate that place cell remapping allows an animal to simultaneously identify its physical location and optimally estimate the identity of the environment.