AFM operates by scanning a sharp tip over the surface of a sample while maintaining a constant force between the tip and the sample surface. The deflection of the cantilever is measured using a laser beam reflected off the back of the cantilever onto a photodetector. The resulting data is used to construct a three-dimensional image of the surface. AFM can be operated in various modes, including contact mode, tapping mode, and non-contact mode, each suitable for different types of samples and measurements.