An undulatory pattern of body bending in which waves pass along the body from head to tail is a major mechanism of creating thrust in many fish species during steady locomotion. Analyses of live fish swimming have provided the foundation of our current understanding of undulatory locomotion, but our inability to experimentally manipulate key variables such as body length, flexural stiffness and tailbeat frequency in freely swimming fish has limited our ability to investigate a number of important features of undulatory propulsion. In this paper we use a mechanical flapping apparatus to create an undulatory wave in swimming flexible foils driven with a heave motion at their leading edge, and compare this motion with body bending patterns of bluegill sunfish (Lepomis macrochirus) and clown knifefish (Notopterus chitala). We found similar swimming speeds, Reynolds and Strouhal numbers, and patterns of curvature and shape between these fish and foils, suggesting that flexible foils provide a useful model for understanding fish undulatory locomotion. We swam foils with different lengths, stiffnesses and heave frequencies while measuring forces, torques and hydrodynamics. From measured forces and torques we calculated thrust and power coefficients, work and cost of transport for each foil. We found that increasing frequency and stiffness produced faster swimming speeds and more thrust. Increasing length had minimal impact on swimming speed, but had a large impact on Strouhal number, thrust coefficient and cost of transport. Foils that were both stiff and long had the lowest cost of transport (in mJ m −1 g −1 ) at low cycle frequencies, and the ability to reach the highest speed at high cycle frequencies.