Fish typically swim by periodic bending of their bodies. Bending seems to follow a universal rule; it occurs at about one-third from the posterior end of the fish body with a maximum bending angle of about
$30^{\circ }$. However, the hydrodynamic mechanisms that shaped this convergent design and its potential benefit to fish in terms of swimming speed and efficiency are not well understood. It is also unclear to what extent this bending is active or follows passively from the interaction of a flexible posterior with the fluid environment. Here, we use a self-propelled two-link model, with fluid–structure interactions described in the context of the vortex sheet method, to analyse the effects of both active and passive body bending on the swimming performance. We find that passive bending is more efficient but could reduce swimming speed compared with rigid flapping, but the addition of active bending could enhance both speed and efficiency. Importantly, we find that the phase difference between the posterior and anterior sections of the body is an important kinematic factor that influences performance, and that active antiphase flexion, consistent with the passive flexion phase, can simultaneously enhance speed and efficiency in a region of the design space that overlaps with biological observations. Our results are consistent with the hypothesis that fish that actively bend their bodies in a fashion that exploits passive hydrodynamics can at once improve speed and efficiency.