A context-driven memory model simulates a wide range of characteristics of waking and sleeping hippocampal replay, providing a new account of how and why replay occurs.