Think Like a Computer
No ads, no affiliate links, no software recommendations you did not ask for.

Reading netstat Output: Columns, States and PIDs

How to read netstat output: what each column of netstat -ano reports, what LISTENING, ESTABLISHED, TIME_WAIT and CLOSE_WAIT mean, and how to map a PID to a process.

The netstat command prints the kernel’s table of open network endpoints: every socket the machine currently holds, in every state it can hold it. It is a snapshot, not a log. Each line is one endpoint, and the columns describe who owns it, what address and port it is bound to, what remote address it is talking to, and where in the TCP lifecycle that conversation currently sits. Once the columns and the state names are understood, the output answers questions the command was never asked directly: which process is holding a port, whether a connection is half-closed, and whether a listener is bound to the address a client is actually dialling.

What netstat -ano adds to the plain listing

Run without switches, netstat prints local and foreign addresses and the state. The three switches that matter for diagnosis are -a, -n and -o.

-a includes listening sockets and UDP endpoints, not just active TCP connections. -n prints addresses and ports as numbers instead of resolving them to names; this is faster and removes a source of confusion, because a reverse lookup that fails or returns a different name than expected makes the output harder to read, not easier. -o adds the owning process ID.

netstat -ano

A typical line has five fields:

  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       1044

The first field is the protocol. The second is the local address and port, in address:port form. The third is the foreign address and port. The fourth is the TCP state. The fifth, present only with -o, is the PID of the process that owns the socket.

A local address of 0.0.0.0 means the socket is bound to every IPv4 address on the machine; [::] is the IPv6 equivalent. A foreign address of 0.0.0.0:0 on a listening socket means no peer is attached yet — the port is open and waiting. On an established connection the foreign address is the actual peer, and the port on the right is the peer’s ephemeral port, not the service port.

The TCP states as points in a connection’s life

The state column is the most useful and the most misread part of the output. TCP states are not error codes; each one describes where a connection is in the open-close handshake defined by the protocol.

LISTENING is the state of a socket that has been bound to a local port and is waiting for incoming connection requests. It has no peer. A service that should be reachable but shows no LISTENING line on the expected port is not running, is bound to a different address, or is bound to a different port.

ESTABLISHED means the three-way handshake completed and both sides consider the connection open. Data can flow. An ESTABLISHED line with a foreign address is a live conversation.

TIME_WAIT appears on the side that initiated the close, after the final acknowledgement. The connection is finished for application purposes, but the kernel holds the socket for a period (twice the maximum segment lifetime) so that delayed duplicate segments from the old connection cannot be mistaken for the new one. TIME_WAIT entries are normal and self-clearing. A large number of them on a busy client is the expected cost of many short-lived outbound connections.

CLOSE_WAIT means the peer sent a FIN and the local application has not yet closed its side. The kernel has acknowledged the peer’s close; the socket stays in CLOSE_WAIT until the application calls close. A socket that sits in CLOSE_WAIT for a long time indicates the application is not releasing the handle — the remote end is gone, the local program has not noticed. This is an application behaviour, not a network fault, and it is the state most often mistaken for a firewall problem.

SYN_SENT means a connection request has been sent and no reply has arrived. It is the state seen when a destination is unreachable or a firewall is dropping the SYN silently.

Mapping a PID to a process with tasklist

The PID in the last column is only useful once it is resolved to a process name. tasklist does that.

tasklist /FI "PID eq 1044"

The filter limits output to the matching process; the columns are image name, PID, session name, session number and memory usage. If the PID belongs to a service hosted in a shared process, the image name will be the host (for example svchost.exe) rather than the service. To see which services run inside a given svchost instance:

tasklist /SVC /FI "PID eq 1044"

The /SVC switch adds a services column listing the service names hosted by that process. This is the step that turns a generic host process into a specific service.

Why -b needs an elevated prompt

The -b switch shows the executable involved in creating each connection or listening port. It requires administrative rights because the information comes from the kernel and is considered sensitive: knowing which executable owns which socket is useful to an attacker as well as an administrator. Run in an ordinary user prompt, -b fails with an access-denied message and the rest of the output is suppressed.

netstat -abno

Run from an elevated command prompt, this combines the executable name, the numeric addresses and the PID. The executable name appears on its own line beneath the connection it belongs to. Where several components are involved, netstat may print a sequence of names; the last is the one that created the endpoint.

Get-NetTCPConnection as the structured equivalent

Windows PowerShell exposes the same table as objects rather than fixed-width text. The cmdlet is Get-NetTCPConnection.

Get-NetTCPConnection -State Listen

This returns only listening endpoints, as objects with properties such as LocalAddress, LocalPort, RemoteAddress, RemotePort, State and OwningProcess. Because the output is objects, it can be filtered and joined. To resolve the owning process name for every established connection:

Get-NetTCPConnection -State Established | Select-Object LocalPort,RemoteAddress,RemotePort,OwningProcess,@{n='Process';e={(Get-Process -Id $_.OwningProcess).ProcessName}}

The calculated property looks up the process name from the PID, doing in one pipeline what netstat plus tasklist does in two commands. The same cmdlet can filter by port:

Get-NetTCPConnection -LocalPort 443

This is the direct way to answer “what is using port 443” without scanning a text listing. UDP endpoints are not covered by this cmdlet; Get-NetUDPEndpoint is the counterpart, and the difference between the two protocols is set out in TCP vs UDP.

Reading the output against what the client is doing

The columns only make sense when read together. A listening socket on 127.0.0.1:8080 is not reachable from another machine, because the loopback address is local only; a client connecting to the machine’s LAN address will see SYN_SENT or a timeout, and the netstat output will show nothing on the expected port. A listener on 0.0.0.0:8080 is reachable on any local address, subject to the firewall. The local-address column therefore answers a question the state column cannot: not whether the port is open, but which addresses it is open on.

Similarly, a connection in ESTABLISHED with a foreign port that changes on every refresh is a client making repeated short-lived connections, not a server. The side with the fixed local port is the listener; the side with the high, changing local port is the client. This distinction matters when deciding which end of a connection to investigate.

When a port must be reached from outside the machine, the address the service binds to and the port the router forwards are two separate settings. The forwarding side is covered in port forwarding; netstat shows only what the local machine is doing with the port once traffic arrives.

What TIME_WAIT and CLOSE_WAIT do not mean

Two misreadings recur. The first is treating a large TIME_WAIT count as a leak or a fault. TIME_WAIT is a deliberate protocol state with a fixed lifetime; entries expire on their own and cannot be closed early through netstat. A high count on a client that opens and closes many connections is the cost of doing business, and the remedy, where one is needed, is connection reuse in the application, not a netstat switch.

The second is treating CLOSE_WAIT as evidence of a blocked port. The port is not blocked; the peer has closed and the local program has not. Checking the firewall will not change a CLOSE_WAIT line. Resolving the PID and looking at that process is the only step that leads anywhere. The same logic applies to SYN_SENT: it points at the path to the destination, not at the local listener.

Filtering a long listing down to the lines that matter

On a busy machine the full listing is hundreds of lines. The -p switch restricts output to one protocol.

netstat -anop TCP

This prints only TCP endpoints, with numeric addresses and PIDs. For a specific port, findstr narrows the text output:

netstat -ano | findstr :3389

The colon before the port prevents matches on unrelated numbers. The result shows every endpoint whose local or foreign address includes that port, which is what is wanted when checking whether a remote desktop listener exists and what owns it. In PowerShell the equivalent filter is the -LocalPort parameter of Get-NetTCPConnection, which avoids text matching entirely.

When the output shows nothing at all

An empty or near-empty listing on a machine that should be listening points at the service, not the network. Confirm the service is running, then confirm the address it binds to. A service configured to bind only to a specific interface will not appear on 0.0.0.0, and a client dialling a different interface will fail while netstat shows a healthy listener on the wrong address. The local-address column is the field that distinguishes the two cases, and it is the one most often skipped when the state column is read first.

Common questions

What does the PID column in netstat -ano mean?

It is the process ID of the process that owns the socket. The PID alone does not name the program; use tasklist with a PID filter, or tasklist /SVC for a shared host process, to resolve it to an image name and any services it hosts.

Why does netstat -b say access is denied?

The -b switch reports the executable behind each endpoint, and that information requires administrative rights. Run the command from an elevated command prompt. In an ordinary prompt the switch fails and the listing is suppressed.

What is the difference between TIME_WAIT and CLOSE_WAIT?

TIME_WAIT is set on the side that closed first, after the final acknowledgement, and clears itself after a fixed interval. CLOSE_WAIT means the peer has closed and the local application has not yet released its side; it persists until the program closes the socket.

How do I find which process is using a port without netstat?

Use Get-NetTCPConnection with the -LocalPort parameter, then read the OwningProcess property or resolve it with Get-Process. The cmdlet returns objects rather than text, so no parsing or findstr filtering is needed.

Why does a port show LISTENING but connections still fail?

Check the local address on the listening line. A listener bound to 127.0.0.1 accepts only local connections; a client on another machine cannot reach it. A listener on 0.0.0.0 accepts connections on any local address, subject to the firewall.

Read next