Humans experience small fluctuations in their gait when walking on uneven terrain. Thefluctuations deviate from the steady, energy-minimizing pattern for level walking and have no obvious organization. But humans often look ahead when they walk, and could potentially plan anticipatory fluctuations for the terrain. Such planning is only sensible if it serves some an objective purpose, such as maintaining constant speed or reducing energy expenditure, that is also attainable within finite planning capacity. Here, we show that humans do plan and perform optimal control strategies on uneven terrain. Rather than maintaining constant speed, they make purposeful, anticipatory speed adjustments that are consistent with minimizing energy expenditure. A simple optimal control model predicts economical speed fluctuations that agree well with experiments with humans (N= 12) walking on seven different terrain profiles (correlated with model[Formula: see text] , [Formula: see text] all terrains). Participants made repeatable speed fluctuations starting about six to eight steps ahead of each terrain feature (up to ±7.5cm height difference each step, up to 16 consecutive features). Nearer features matter more, because energy is dissipated with each succeeding step's collisionwith ground, preventing momentum from persisting indefinitely. A finite horizon of continuous look-ahead and motor working space thus suffice to practically optimize for any length of terrain. Humans reason about walking in the near future to plan complex optimal control sequences.