Antivirus programs work by scanning files and comparing them against a database of known virus definitions. They use various techniques such as signature-based detection, heuristics, and behavior-based detection to identify and mitigate threats. The software can remove or quarantine infected files to prevent further damage.