The short answer

Before any data moves over TCP, the two ends agree to talk in a three-way handshake: the client sends SYN, the server answers SYN-ACK, and the client confirms with ACK. How a server answers that first SYN is what makes a port open, closed or filtered.

  • Open: the server replies SYN-ACK. A program is listening and the connection opens.
  • Closed: the server replies RST (reset). The machine is up, but nothing listens on that port.
  • Filtered: nothing comes back before the client gives up. A firewall silently dropping the SYN is the usual cause, but packet loss, a routing problem or a host that is down look the same from outside.

You can see which one a port gives you with the TCP Port Check, which draws a schematic of the handshake inferred from the connection result. It does not capture packets.

The three-way handshake

TCP is defined in RFC 9293, which replaced the original RFC 793 in 2022. Each side picks a random starting sequence number, and the handshake is how each learns the other’s:

  1. SYN: the client sends a segment with the SYN flag and its initial sequence number, to the server’s address and port, from a temporary (ephemeral) port of its own.
  2. SYN-ACK: if a program is listening, the server’s operating system answers with SYN and ACK set, its own sequence number, and an acknowledgment of the client’s.
  3. ACK: the client acknowledges the server’s sequence number. The connection is now established, and either side can send data.

The handshake costs one round trip before the first byte of data, which is why the time it takes to connect is a good rough measure of network latency between two points. TLS, HTTP and every other protocol on top of TCP add their own round trips after it.

The operating system completes the handshake, not the application. A server can accept the connection and then do nothing, which is why an open port proves that something is listening, not that the service behind it works.

Open, closed and filtered

The same SYN gets one of three answers:

How a TCP port answers when it is open, closed or filteredOpen: the client sends SYN, the server replies SYN-ACK and the client sends ACK, so the connection opens. Closed: the client sends SYN and the server replies RST at once. Filtered: the client sends SYN, a firewall drops it, the client retries and finally times out with no reply. Open Client Server port SYN SYN-ACK ACK Connected Closed Client Server port SYN RST Refused at once Filtered Client Server port SYN SYN (retry) Firewall No reply, times outHow a TCP port answers when it is open, closed or filteredOpen: the client sends SYN, the server replies SYN-ACK and the client sends ACK, so the connection opens. Closed: the client sends SYN and the server replies RST at once. Filtered: the client sends SYN, a firewall drops it, the client retries and finally times out with no reply. Open Client Server port SYN SYN-ACK ACK Connected Closed Client Server port SYN RST Refused at once Filtered Client Server port SYN SYN (retry) Firewall No reply, times out
The same connection attempt against an open, a closed and a filtered port. Only the open port completes the handshake.
StateWhat comes backWhat it usually means
OpenSYN-ACKA service is listening and the path allows the connection.
ClosedRST, straight awayThe host is reachable but nothing listens on the port, or a firewall is set to reject with a reset.
FilteredNothing, until a timeoutA firewall, security group or router dropped the SYN. The host may also be down.
RejectedAn ICMP “unreachable” messageA firewall rejected the SYN with ICMP rather than dropping it. Most tools report this as closed or unreachable.

A closed port is not a failure of the network: the RST is the host saying “nothing here” quickly and honestly. A filtered port is ambiguous by design. Dropping packets silently gives an outsider no way to tell whether the host exists, which is why most firewalls drop rather than reject traffic from the internet.

Port scanners such as Nmap use the same three words. Nmap also has open|filtered and closed|filtered for scan types that can’t tell those states apart; a full connection attempt, like the one described here, always can.

Why a filtered port takes so long

When a SYN gets no answer, the client can’t know whether it was lost or dropped, so it sends it again with a growing wait between tries. RFC 6298 sets the first retransmission timeout at one second and doubles it each time.

  • Linux tries six more times by default (net.ipv4.tcp_syn_retries), so a connection to a filtered port can hang for about two minutes.
  • Windows gives up after about 21 seconds by default, which is why Test-NetConnection takes a while before it reports a failure.
  • Tools such as nc -w 5 or the TCP Port Check set their own, shorter limit.

A fast failure and a slow one tell you different things. A refusal within milliseconds means you reached the host. A long silence means something in the path is discarding your packets.

Common reasons a port isn’t open

  • The service isn’t running, or it crashed. The host answers RST.
  • It listens on the wrong address. A service bound to 127.0.0.1 or ::1 accepts connections only from the same machine. From anywhere else, the port is closed.
  • A host firewall such as Windows Defender Firewall, nftables, firewalld or ufw blocks the port. These usually drop, so the port looks filtered.
  • A cloud security group or network ACL doesn’t allow the port, or allows it only from some source addresses. Cloud providers drop by default.
  • NAT without a port forward. A home or office router has no rule sending the port to the machine behind it. See NAT and private IP ranges.
  • The provider blocks it. Many residential and cloud networks block outbound port 25, and some block inbound ports such as 80 or 445 for home connections.
  • IPv4 works but IPv6 doesn’t, or the other way round. A name with both A and AAAA records can give different answers for each, because firewalls often have separate rules for each family.

How to test a port yourself

Only test systems you own or have permission to test. Each of these makes a full connection attempt, like the handshake above:

SystemCommand
Windows PowerShellTest-NetConnection example.com -Port 443
macOS and Linuxnc -vz -w 5 example.com 443
Linux, without netcattimeout 5 bash -c '</dev/tcp/example.com/443' && echo open
Any system with curlcurl -v telnet://example.com:22

To see what a server itself is listening on, run ss -tlnp on Linux, lsof -iTCP -sTCP:LISTEN -n -P on macOS or Get-NetTCPConnection -State Listen in PowerShell. A port that is listening on the server but filtered from outside points to a firewall in between.

Test from more than one place when you can. A check from your own computer, from the server’s own network and from the internet, such as the TCP Port Check running on Cloudflare, narrows down which hop is blocking the connection.

Services that speak first

Once the handshake completes, some protocols wait for the client and some greet it. SSH sends a version line such as SSH-2.0-OpenSSH_9.6, and SMTP, FTP, POP3 and IMAP servers send a greeting that starts with a status code. HTTP, TLS and most databases send nothing until the client speaks. Reading that first line, often called banner grabbing, is a quick way to confirm which service is behind a port. Because a version string helps an attacker look up known vulnerabilities, many teams trim it.

FAQ

Does an open port mean a server is insecure?

No. An open port only means something answers there. Web and mail ports are meant to be open. The risk depends on the service behind the port and who is allowed to reach it; remote desktop, file sharing and database ports should normally be limited to a VPN or known addresses.

Why does a port show as filtered from one place and open from another?

Firewalls and cloud security groups often allow a port only from certain source addresses, and network paths differ. A port allowed from your office but not from the internet is open from one and filtered from the other.

Can I tell closed and filtered apart with ping?

No. Ping uses ICMP, not TCP, and many hosts and firewalls block it even when TCP ports are open. Test the TCP port itself.

What is a half-open or SYN scan?

A scan that sends SYN and, on a SYN-ACK, answers with RST instead of completing the handshake. It is faster and less likely to be logged by the application, but it needs raw packet access. A full connect, as used by netcat, Test-NetConnection and the TCP Port Check, completes the handshake and then closes.

Sources and further reading