Interfacial perpendicular magnetic anisotropy in the MgO/Co2FeAl heterostructure is desired for technological applications, while its origin of the large interfacial anisotropy constant (Ki) remains controversial. Here we show that, by modeling four types of interface models for MgO/Co2FeAl system using first-principles calculations, the MgO/Co2 interface is energetically more favorable than MgO/FeAl interface, and the interfacial Co atoms at the former interface produce out-of-plane Ki while the interfacial Fe atoms at the later interface produce in-plane Ki. The origin of this different behavior can be explained from the atomic-resolved and orbital-resolved Ki along with the perturbation theory energy analysis. In addition, we also studied the influence of 26 capping layers on the interfacial magnetic anisotropy of MgO/Co2FeAl and found that Fe-and W-capping can significantly enhance the Ki in the MgO/Co2FeAl with a particularly large Ki of 4.90 mJ/m 2 in the W-capped model. This work clarifies the atomistic origin of the interfacial perpendicular magnetic anisotropy and provides guidance to further enhance interfacial Ki by adding capping layers in the MgO/Co2FeAl.