In this study, we analyze the effects of thermal annealing by calculating the optical gain in the InGaN/GaN quantum well. The interdiffusion of Ga and In atoms across the interface of the well and the barrier resulting from thermal treatments is described by Fick's law. The strong piezoelectric effect due to lattice mismatch in the InGaN/GaN quantum well is also considered in the calculation. The results confirm that the thermal annealing can induce an increase of the optical gain. However, an excessive annealing might result in decreasing the optical gain in the InGaN/GaN quantum well. The maximum optical gain can be obtained at a diffusion length of 4Å of In and Ga atoms. There is a good agreement between the experimental data in literature and the optimized diffusion length studied in this work.