A fish may gain hydrodynamic benefits from being a member of a school. Inspired by fish schools, a two-dimensional simulation was performed for flexible fins propelled in tandem, diagonal, triangular and diamond configurations. The flow-mediated interactions between the flexible fins were analysed by using an immersed boundary method. A transverse heaving motion was prescribed on the leading edge of each fin, and other posterior parts passively adapted to the surrounding fluid as a result of the fluid–flexible-body interaction. The flexible fins were allowed to actively adjust their relative positions in the horizontal direction. The four basic stable configurations are spontaneously formed and self-sustained purely by the vortex–vortex and vortex–body interactions. The hydrodynamic benefits depend greatly on the local positions of the members. For the same heaving motion prescribed on the leading edge, the input power of the following fin in the stable tandem and diagonal configurations is lower by 14 % and 6 %, respectively, than that of the leading fin. The following fin in the diagonal formation can keep pace with the leading fin even for reduced heaving amplitudes because of the help of the leader via their shared fluid environment, where its required input power is reduced by 21 %. The heaving amplitudes of the trailing fins are reduced to optimize the propulsive efficiency, and the average efficiencies in the triangular and diamond configurations increase by up to 14 % and 19 %, respectively, over that of the isolated swimmer. The propulsive efficiencies are enhanced by 22 % for the fins in the second row and by 36 % for the fin in the third row by decreasing the heaving amplitude in the diamond formation.