Fish maintain high swimming efficiencies over a wide range of speeds. A key to this achievement is their flexibility, yet even flexible robotic fish trail real fish in terms of performance. Here, we explore how fish leverage tunable flexibility by using their muscles to modulate the stiffness of their tails to achieve efficient swimming. We derived a model that explains how and why tuning stiffness affects performance. We show that to maximize efficiency, muscle tension should scale with swimming speed squared, offering a simple tuning strategy for fish-like robots. Tuning stiffness can double swimming efficiency at tuna-like frequencies and speeds (0 to 6 hertz; 0 to 2 body lengths per second). Energy savings increase with frequency, suggesting that high-frequency fish-like robots have the most to gain from tuning stiffness.