Atomic Force Microscopy (AFM) has various imaging modes, and tapping mode is the most commonly used scanning approach. Tapping mode allows for the acquisition of both height and phase information from the sample surface, with phase information being particularly valuable as it reflects the physical properties of the sample surface. To understand the mechanism behind phase imaging in AFM, this study derived theoretical expressions for phase using both vibration theory and energy theory. It was found that the phase expressions obtained from these two theoretical methods are fundamentally consistent. The theoretical results revealed that phase is directly related to background dissipation and excitation frequency. The presence of background dissipation can mask information from the sample surface and reduce phase contrast, while the excitation frequency also has a significant impact on phase. Through theoretical and experimental analyses, this paper identified an optimal excitation frequency during scanning that maximizes phase contrast. These findings are crucial for understanding phase imaging in AFM and, consequently, optimizing phase imaging in experiments.