AFM uses a cantilever with a sharp tip to scan the surface of a sample. As the tip moves across the surface, it deflects due to interactions with the sample, and these deflections are measured to create a topographical map. AFM can be used in various environments, including air, liquid, and vacuum, making it versatile for studying different types of nanomaterials.