Network security

What Is a Port Scan? How Port Scanning Works, Types and Is It Legal?

A port scan is a knock on every door of a computer to see which ones answer. Here is how it works, what open, closed and filtered mean, and how to use it safely.

Cysoro Security TeamPublished · 9 min read
scanme.example — ports 22/tcp open sshOpenSSH 9.8 443/tcp open httpsnginx 1.26 3306/tcp closedno service listening 8080/tcp filteredfirewall drops probes $ nmap -sS scanme.example NETWORK SECURITY Portscan Knocking on every door.
Quick answer

A port scan is a technique that sends connection requests to the numbered network ports on a computer or server to find out which ports are open, closed or filtered. Security teams use it to find exposed services and misconfigurations, while attackers use the same technique to find a way in. Scanning your own systems is legitimate; scanning systems you do not own without permission is not.

Key takeaways

  • A port scan tests each network port and reports it as open, closed, filtered or open-filtered.
  • A SYN scan is the standard method: it sends the first packet of a TCP handshake and reads the reply without completing the connection.
  • Open ports are not automatically dangerous, but an unexpected open port is a finding worth investigating and closing.

Every computer connected to a network has 65,535 numbered doors, called ports. A port scan knocks on them, one by one, and notes which ones answer. It is one of the oldest and most useful techniques in network security.

What is a port scan?

A port scan is a method of probing a computer or server to discover which network ports are open and what services are listening on them. The scanner sends a small packet to each port and records the reply, or the lack of one.

Think of a port as a numbered door for a specific kind of traffic. Port 443 is the door for encrypted web traffic, port 22 is the door for SSH, and port 53 is the door for DNS. A server that hosts a website needs port 443 open. A laptop that browses the web needs almost none open.

Port scanning is a dual-use technique. Your IT team runs it to find forgotten services, misconfigured firewalls and exposed databases before an attacker does. An attacker runs the same scan to find a way in. The packets are identical; the permission and the intent are what differ.

Scanners range from the free, open-source tool Nmap to built-in operating system commands and online checkers. Nmap is the standard tool for this work, and its documentation is the reference for the scan types described in this article.

How does a port scan work?

A port scan works by sending a probe packet to a target port and interpreting the response. An open port replies in a way that shows a service is listening, a closed port replies with a reset, and a filtered port sends no reply at all.

For TCP, the most common protocol, the probe usually starts the three-way handshake: the scanner sends a SYN packet, the target replies with SYN-ACK if the port is open, and the scanner normally finishes with an ACK. Different scan types stop at different points in that handshake, which changes how visible and how reliable the scan is.

For UDP, which has no handshake, the scanner sends an empty or protocol-specific packet and waits. An ICMP port-unreachable message means the port is closed. A reply from a service means it is open. No reply at all means the port is open or filtered, and the scanner cannot tell which.

Scans can cover a single host, a whole network range, or just the most common 1,000 ports. Scanning all 65,535 TCP ports on one host is called a full scan, and it takes much longer than a quick scan of the top ports.

How a SYN scan reads each port Scannersends SYN toeach portSYN Target serverreplies per portACK Port 22: SYN-ACK = openPort 443: SYN-ACK = openPort 3306: RST = closed No reply at all usually means a firewall filtered the probe.
A SYN scan sends one probe per port and reads the reply to classify each port. Illustration by Cysoro.

What do open, closed and filtered mean?

Every port a scanner tests ends up in one of a few states. Open means a service is listening, closed means nothing is listening, and filtered means a firewall or filter blocked the probe so the scanner cannot tell.

StateWhat it meansWhat to do
OpenA service is listening and will accept connectionsConfirm you expect this service, keep it patched
ClosedThe host replied that nothing listens hereNormal for most ports; no action needed
FilteredNo reply; a firewall probably dropped the probeCheck the firewall rule matches your intent
Open|filteredUDP only: no reply, so either is possibleProbe the service directly or check the host
UnfilteredReachable, but open or closed is unknownSeen with ACK scans that map firewalls

An open port is not automatically a vulnerability. A web server must have port 443 open, and a mail server needs port 25 or 587. The risk comes from open ports you did not expect, services running old versions, and services that should never face the internet, such as a database on port 3306 or remote desktop on port 3389.

Filtered is often the state you want for ports that must stay closed to the outside world. It tells an attacker nothing, while a closed reply at least confirms the host exists. That is why many firewalls are set to drop, not reject, unwanted traffic.

What are the main types of port scan?

The main scan types are TCP SYN, TCP connect, UDP, and the stealth FIN, NULL and Xmas scans. Each sends different packets, needs different privileges, and trades speed, stealth and accuracy against each other.

TCP SYN scan (-sS)

The SYN scan is the default in Nmap and the most popular scan type. It sends only the first packet of the handshake and never completes the connection, so it is fast and relatively quiet. A SYN-ACK reply means open, a reset means closed, and silence means filtered.

It needs raw packet privileges, which usually means running as root on Linux or as an administrator on Windows. Nmap documents it as the default and most popular option for good reasons, including speed and clear differentiation between open, closed and filtered states, in its port scanning techniques guide.

TCP connect scan (-sT)

A connect scan completes the full three-way handshake using the operating system's normal connect call. It works without special privileges, which makes it the fallback when a SYN scan is not possible. It is slower, creates a full connection that services may log, and is therefore easier to spot.

UDP scan (-sU)

A UDP scan sends a packet to each UDP port and waits for an ICMP unreachable error or a service reply. It is slower and less reliable than TCP scanning because open UDP ports often send no reply at all. Still, skipping UDP is a mistake: DNS, DHCP and SNMP all run over UDP, and attackers do not ignore them.

FIN, NULL and Xmas scans (-sF, -sN, -sX)

These scans exploit a detail in the TCP specification, RFC 793: a closed port should reply with a reset to a packet without SYN, RST or ACK flags, while an open port should drop it silently. They can slip past some simple firewalls, but many systems, including Windows, reply with a reset regardless, which makes every port look closed.

ACK scan (-sA)

An ACK scan never finds open ports. Instead, it maps firewall rules by sending ACK packets and seeing which ports reply with a reset (unfiltered) and which stay silent (filtered). It is a reconnaissance tool for understanding a firewall, not for finding services.

Which ports do scanners check first?

Scanners usually start with the most common ports, because a handful of services account for most exposed systems. The top 1,000 ports cover the services attackers most often target, and a quick scan of them takes seconds.

PortServiceWhy it matters
22SSHRemote server access; target for password attacks
80HTTPUnencrypted web traffic
443HTTPSEncrypted web traffic; expected on web servers
53DNSName resolution; open resolvers can be abused
25 / 587SMTPMail sending; open relays send spam
3389RDPWindows remote desktop; a top ransomware entry point
3306MySQLDatabase; should almost never face the internet
445SMBWindows file sharing; exploited by past worms

Port numbers are assigned by IANA, which maintains the official registry of service names and port numbers. Well-known ports run from 0 to 1023, registered ports from 1024 to 49151, and dynamic ports from 49152 to 65535. Knowing the registry helps you recognize a service from a port number alone.

When you review scan results, ask three questions about each open port: did I expect this service, does it need to be reachable from the internet, and is it running the latest patched version? If any answer is no, you have work to do.

Port scanning is legal when you scan systems you own or have written permission to test. Scanning other people's systems without permission can be illegal and can also breach your provider's terms of service, even if you meant no harm.

In the United States, unauthorized access laws are written broadly, and courts have treated aggressive scanning as part of unauthorized access in some cases. In the UK, the Computer Misuse Act covers unauthorized access to computer material. The practical rule is simple: get permission in writing before you scan anything that is not yours.

That includes public websites and cloud servers. A site being reachable on the internet does not mean you have permission to scan it. Security researchers use bug bounty programs and responsible disclosure policies, which define exactly what testing is allowed.

Even authorized scans need care. Tell the system owner when you will scan, scan during quiet hours where possible, and keep the rate low on fragile systems. If you run a scan from a work network, check your employer's policy first, because scans often trigger security alerts.

How do you defend against port scans?

You cannot stop someone from sending packets to your ports, but you can make the results boring. Close unused ports, put a firewall in front of what remains, and keep every exposed service patched and protected by strong authentication.

Start with the firewall. Only the ports your services need should be reachable, and only from the networks that need them. A database should accept connections from your application servers, not from the whole internet. Remote administration should sit behind a VPN, not on a public port. CISA makes the same point in its Shields Up guidance: disable ports and protocols that are not essential for business purposes.

Next, reduce what a scan reveals. Disable banner information that advertises exact software versions where you can, and use a firewall that drops unwanted probes instead of rejecting them. Intrusion detection systems can alert you when one address probes many ports in a short time, which is the classic signature of a scan.

Finally, scan yourself regularly. A monthly scan of your own public addresses catches the port a colleague opened for a test and forgot, or the new service a vendor installed with a default configuration. Our guide to securing your Wi-Fi covers the same close-what-you-do-not-need habit for home networks.

Five controls that make a scan boring 1. Close unused portsif nothing listens, there is nothing to exploit 2. Firewall by default denyallow only the ports and sources you need 3. Patch exposed servicesan open port with an old version is the risk 4. Hide admin access behind a VPNSSH and RDP should never be public 5. Scan yourself monthly
Defense is mostly hygiene: fewer open ports, tighter firewalls and regular self-scans. Illustration by Cysoro.

How do I run a port scan on my own network?

Run a scan only on systems you own or have written permission to test. On your own network, install Nmap, pick a target you control, and start with a slow scan of the most common ports.

A safe first command is nmap -sV --top-ports 100 192.168.1.1 against your own router, replacing the address with your own device. The -sV flag asks Nmap to identify the service version on each open port, which is the detail that matters for patching.

Read the output port by port. For each open port, note the service and version, then check whether you recognize it. A port you cannot explain is a finding, not a mystery to ignore: look up which program on the host is listening, and close it or firewall it if it is not needed.

You can also check your public address from outside your network. Find your public IP with our what is my IP tool, then scan that address from a machine outside your home network, or ask a trusted friend to run the scan for you. Compare the external view with your internal view.

Never scan a target you do not ownScanning a stranger's server, a public website or a cloud IP without written permission can break the law and your provider's rules, even if the scan itself is harmless.

The bottom line

A port scan is a simple idea with serious consequences: it maps exactly which services a computer exposes to the network. Used on your own systems, it is one of the cheapest ways to find misconfigurations before an attacker does.

Learn the states, learn the SYN scan, and make a monthly self-scan part of your routine. You can start by checking what your own network exposes with the free DNS lookup tool and the attack surface checks on the Cysoro platform.

Frequently asked questions

What is a port scan in simple terms?

A port scan is a check that tries to connect to the numbered doors, called ports, on a computer. Each reply tells the scanner whether a service is listening on that port, nothing is listening, or a firewall is blocking the probe.

Is port scanning illegal?

Scanning your own computers and networks is legal. Scanning someone else's systems without permission can break computer misuse laws in the US, UK and EU, and can get your account suspended by your internet provider or cloud host. Always get written permission first.

What does an open port mean?

An open port means a program on that computer is listening for connections on that port, such as a web server on port 443. It is normal for servers to have some open ports, but every open port is a service an attacker can try to exploit.

What is the difference between open, closed and filtered?

Open means a service answered. Closed means the computer replied that nothing is listening. Filtered means no reply came back, usually because a firewall dropped the probe, so the scanner cannot tell whether a service is there.

What is a SYN scan?

A SYN scan sends only the first packet of the TCP handshake, called SYN, and reads the reply. A SYN-ACK reply means the port is open, a reset means it is closed, and no reply means it is filtered. It never completes the connection.

Can a port scan damage my computer?

A normal scan is low risk, but aggressive scans can crash fragile services, fill up logs, or trigger intrusion detection alerts. Scan slowly, avoid production systems during busy hours, and never scan medical or industrial equipment without expert approval.

How do I check my own open ports?

On your own network, run a scanner such as Nmap against your own IP address or use an online port checker for your public address. Compare the results with the services you expect to be running, and close or firewall anything unexpected.

Why do attackers port scan?

Attackers scan to find exposed services such as remote desktop, databases and old web servers. Once they find an open port, they check the service version and try known vulnerabilities, weak passwords or default credentials on that service.

Sources

  1. Nmap — Port Scanning Techniques
  2. CISA — Shields Up: Guidance for Organizations
  3. DigitalOcean — Nmap Switches and Scan Types
  4. Oklahoma Cyber Command — Shields Up: A U.S. Homeland Initiative
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against the Nmap port scanning documentation and CISA Shields Up guidance.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free