Optiv interview question

How does an nmap port scan work?