Nmap Cheat Sheet: Scan Types, Port States and Commands Explained [Interactive Lab]

PRACTICAL LEARNING8 min read

Nmap (Network Mapper) is the free, open-source tool that network administrators and penetration testers use to find which hosts are online, which ports are open and which services and versions run behind them. The command you will run most is nmap -sV target: it scans the 1000 most common TCP ports and identifies each service it finds.

This page is a working Nmap cheat sheet. Start with the interactive lab to see what really happens on the wire during a scan, then use the tables below as a reference. Only scan systems you own or have written permission to test. The Nmap project runs scanme.nmap.org so you can practise legally.

Interactive Nmap lab

In Lab 1, switch between scan types and target situations and watch the packets that decide whether Nmap says open, closed or filtered. In Lab 2, build a real command and read what every flag does before you run it.

Lab 1 ยท Port states
Watch the packets behind open, closed and filtered
Pick a scan type and what is really happening on the target port. The diagram shows what Nmap sends, what comes back, and the state Nmap reports.
Scan type
On the target port
openPORT 443/tcp
Lab 2 ยท Command builder
Build an Nmap command and see what every flag does
Only scan systems you own or have written permission to test. scanme.nmap.org is run by the Nmap project for exactly this kind of practice. Keep it to a few scans a day.
Target
Host discovery
Scan type
Ports
Speed
Save results
Extra checks
nmap

    Nmap cheat sheet: the commands you will actually use

    CommandWhat it does
    nmap 192.168.1.10Scan the 1000 most common TCP ports on one host
    nmap 192.168.1.0/24Scan a whole subnet (256 addresses)
    nmap -sn 192.168.1.0/24Only find live hosts, no port scan
    nmap -Pn targetSkip host discovery and scan even if the host ignores ping
    nmap -p 22,80,443 targetScan only the ports you list
    nmap -p- targetScan all 65535 TCP ports
    nmap -F targetFast scan of the 100 most common ports
    nmap -sV targetDetect the service and version on each open port
    nmap -O targetGuess the operating system (needs root)
    nmap -sC targetRun the default set of safe NSE scripts
    nmap -A targetAggressive: OS detection, versions, default scripts and traceroute
    nmap -sU --top-ports 50 targetScan the 50 most common UDP ports (needs root)
    nmap -T4 targetFaster timing on a reliable network
    nmap --reason --open targetShow why each port got its state, and only list open ports
    nmap -oA recon targetSave results as recon.nmap, recon.xml and recon.gnmap
    nmap --script-help defaultRead what the default scripts do before you run them

    Nmap scan types: SYN vs connect vs UDP

    The scan type decides which packets Nmap sends. You can see each one in Lab 1 above.

    ScanHow it worksRoot neededUse it when
    -sS SYNSends SYN, reads the reply, then resets without finishing the handshakeYesDefault choice: fast and reliable
    -sT ConnectCompletes the full TCP handshake through the operating systemNoYou cannot run Nmap as root
    -sU UDPSends UDP probes and waits for replies or ICMP errorsYesLooking for DNS, SNMP, DHCP, VPN services
    -sA ACKSends ACK packets to see which ports a firewall lets throughYesMapping firewall rules, not finding open ports

    If you run Nmap with root rights, it uses a SYN scan by default. Without root, it falls back to a connect scan. UDP scanning is slow because closed UDP ports answer with ICMP messages that most systems rate-limit, so start with --top-ports instead of all 65535 ports.

    The six Nmap port states

    StateWhat it means
    openA program is accepting connections on this port
    closedThe host answered, but nothing is listening on the port
    filteredA firewall or filter blocks the probe, so Nmap cannot tell if the port is open
    unfilteredThe port is reachable, but Nmap cannot tell if it is open or closed (seen with -sA)
    open|filteredNo reply at all, typical for UDP: open but silent, or filtered
    closed|filteredNmap cannot tell closed from filtered (only with the rarely used idle scan)

    Add --reason to any scan and Nmap prints the evidence behind each state, such as syn-ack, reset or no-response. It is the fastest way to understand a confusing result.

    Host discovery: is the target even up?

    Before scanning ports, Nmap checks which targets are alive. With root rights it sends an ICMP echo request, a TCP SYN to port 443, a TCP ACK to port 80 and an ICMP timestamp request. On your local network it uses ARP instead, which is faster and more reliable. Without root it tries TCP connections to ports 80 and 443.

    • -sn runs only this discovery step. It is the quickest way to list the live devices on a network.
    • -Pn skips discovery and treats every target as online. Use it when a host blocks ping, otherwise Nmap may report it as down and never scan it.
    • -PS22,80,443 or -PE choose your own discovery probes when the defaults are blocked.

    Nmap timing templates T0 to T5

    TemplateNameWhen to use it
    -T0ParanoidExtremely slow, one probe at a time with long pauses
    -T1SneakyVery slow, to stay under simple detection thresholds
    -T2PoliteSlower, to avoid loading fragile devices or networks
    -T3NormalThe default
    -T4AggressiveFaster, a good choice on modern, reliable networks
    -T5InsaneVery fast, but you start losing results on real networks

    A simple Nmap recon workflow

    Professional testers rarely run one giant scan. They work in layers, from cheap to expensive:

    1. Confirm the scope in writing. Know exactly which IP ranges and hostnames you may scan, and when.
    2. Find live hosts with nmap -sn 10.0.0.0/24 -oA hosts.
    3. Scan the common ports fast with sudo nmap -sS -T4 --open -oA quick and the live hosts.
    4. Scan every port on the interesting hosts with -p-. Services often hide on high ports.
    5. Identify what is running on the open ports only: nmap -sV -sC -p 22,80,8443 target.
    6. Check the top UDP ports with sudo nmap -sU --top-ports 50 target.
    7. Save everything with -oA and write down what each open service is and why it matters.

    Once you know a service and its version, the next step is grabbing and reading its banner. See banner grabbing explained.

    How to read Nmap output

    Here is typical output from a version scan of the practice host. Your results will differ over time.

    $ nmap -sV --reason scanme.nmap.org
    
    PORT      STATE SERVICE    REASON         VERSION
    22/tcp    open  ssh        syn-ack ttl 53 OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.13 (Ubuntu Linux; protocol 2.0)
    80/tcp    open  http       syn-ack ttl 53 Apache httpd 2.4.7 ((Ubuntu))
    9929/tcp  open  nping-echo syn-ack ttl 53 Nping echo
    31337/tcp open  tcpwrapped syn-ack ttl 53
    • PORT is the port number and protocol.
    • STATE is one of the six states above.
    • SERVICE is Nmap’s guess at the service. Without -sV it only looks the port number up in a list, so a web server on port 22 would still be called “ssh”.
    • REASON is the packet that decided the state, here a SYN/ACK.
    • VERSION is the product and version Nmap identified. This is what you research next.
    • tcpwrapped means the connection was accepted and then closed immediately, often by a wrapper or firewall in front of the service.

    Nmap itself is a legal, widely used administration and security tool. What matters is what you scan. Scanning networks you do not own or have permission to test can break the law in many countries and the terms of your internet provider or cloud host. Practise on your own lab, on scanme.nmap.org (a few scans a day), or on training platforms. On real engagements, always have a signed scope. This is general guidance, not legal advice.

    Frequently asked questions

    What does nmap -A do?

    It turns on aggressive detection: operating system detection (-O), service version detection (-sV), the default scripts (-sC) and traceroute. It gives a lot of information in one command, but it is slower and noisier than running only what you need.

    What is the difference between -sS and -sT?

    A SYN scan (-sS) sends a SYN and resets the connection as soon as the target replies, without finishing the handshake. It needs root rights and is faster. A connect scan (-sT) completes the full TCP handshake through the operating system. It works without root, but is slower and easier for the target application to log.

    Why does Nmap show ports as filtered?

    Filtered means Nmap got no useful answer, usually because a firewall drops the probes or answers with an ICMP "administratively prohibited" message. Nmap cannot tell whether the port behind the filter is open. Add --reason to see the evidence for each port.

    How do I scan all ports with Nmap?

    Use -p- to scan all 65535 TCP ports, for example nmap -p- target. By default Nmap only scans the 1000 most common ports, so services on unusual high ports are missed without -p-.

    How do I scan UDP ports with Nmap?

    Use -sU with root rights, for example sudo nmap -sU --top-ports 50 target. UDP scans are slow because closed ports reply with rate-limited ICMP messages and open ports often do not reply at all, which Nmap reports as open|filtered.

    Nmap is a legal tool, but scanning systems without permission can be illegal and usually breaks provider terms. Only scan networks you own, have written permission to test, or that are provided for practice such as scanme.nmap.org.

    Go deeper: the Nmap NSE scripts guide explains the 14 script categories, which scripts are safe to run and the ones worth learning first.

    Where to go next

    This cheat sheet covers what you need for everyday scanning. Reading scan traffic in detail, mapping firewall rules, NSE scripts, OS detection and web server reconnaissance are covered lesson by lesson in Network Reconnaissance Architecture: Advanced Nmap Scans.