We calculated the exchange energy of a pair of donor-bound electrons placed in the middle of an infinite quantum well (QW). In order to obtain this energy for any interdonor distance and for any QW thickness, we have first adapted to a QW the method developed by Gor'kov and Pitaevskii [L. P. Gor'kov and L. P. Pitaevskii, Dokl. Akad. Nauk SSSR 151, 822 (1963)] for a three-dimensional (3D) distribution of donors, and calculated the asymptotic form of the exchange energy. Second we have calculated the exchange energy of a "helium atom" in a QW; and third, inspired by the interpolation procedure proposed by Ponomarev et al. [I.V. Ponomarev et al., Phys. Rev. B 60, 5485 (1999)], we have obtained an interpolated expression for any interdonor distance. The obtained exchange energy is written in units of effective hartree, and the distance between the donors, as well as the width of the QW, are expressed in units of effective Bohr radius. We calculated the exchange energy for some commonly studied semiconductor materials, and discussed also the relationship between the exchange energy and the spin relaxation time for a donor concentration close to the insulator-metal transition.