For the purpose of reducing the effect of positioning system errors in subapert ure stitching interferometry an optimal mechanical error compensation algorithm is proposed by introducing the c ompensator of position correction into the general stitching algorithm.Aiming at decreasing the effect of the unknown reference surfaces, this stitching algorithm best-fits a Zernike polynomial representation of the r eference using maximum likelihood estimation,and then stitches subaperture phases to get the full aperture phase u sing the optimal mechanical error compensation algorithm after the reference surface is subtracted from each measurement data of subaperture.Th e simulation results show that the difference of RMS of the full aperture surface error using the mechanical error compensation algorithm is only as 1/6of that of the general stitching met hod,indicating the stitching precision of mechanical error compensation algorithm is higher than that of the general stitc hing method with the same mechanical precision.In order to experimentally verify the optimal mechanical error compens ation algorithm,a Φ280mm flat mirror is tested by subaperture stitching interferometry and full aperture inter ferometry.The difference of the PV and RMS of the full aperture surface are 0.0994λ and 0.0068λ af ter stitching,indicating that the optimal algorithm can effectively compensate positioning system errors based on the esti mation of the reference wave.