guide · static export
PC · network

Find What Is Using a Port and Free It

A server refuses to start because port 8080 is taken, and the error names nothing useful. Three commands map the port to a process, and one more tells you whether Windows reserved it.

by@guidox updated:10/31/26 time:15 min level:Beginner tested on:Windows 11 24H2 works on:Windows 10, Windows 11, Windows Server 2019 tools:PowerShell as administrator
TL;DR

List listeners with **Get-NetTCPConnection -State Listen**, map the **OwningProcess** to a program, and check **netsh int ipv4 show excludedportrange** before you fight a port Windows reserved.

Before you start

Requirements

  • Admin rights for full process details
  • 20 minutes
Step by step

Instructions

01

Find the listener

**Get-NetTCPConnection** shows the local address, the port and the owning PID. Filter by state first, because a port in TIME_WAIT is not the same problem as a listener.

Get-NetTCPConnection -State Listen | Sort-Object LocalPort |
  Select-Object LocalAddress,LocalPort,OwningProcess | Format-Table -AutoSize
02

Confirm UDP as well

DNS, game servers and discovery services listen on UDP, which the TCP table does not show. Checking only TCP is why some ports look free and still fail.

Get-NetUDPEndpoint | Sort-Object LocalPort | Select-Object LocalAddress,LocalPort,OwningProcess | Format-Table -AutoSize
netstat -ano | findstr :8080
03

Turn the PID into a program

**Get-Process** names the executable and its publisher. An empty Path means a SYSTEM process; run the query elevated to see it.

Get-Process -Id 4032 | Select-Object Id,ProcessName,Path,Company,StartTime
Get-CimInstance Win32_Service | Where-Object ProcessId -eq 4032 | Select-Object Name,DisplayName,StartMode
04

Check whether Windows reserved the port

Hyper-V, Docker and WSL ask Windows to reserve port ranges. Reserved ports are invisible in the connection table and produce an access-denied error for every app that tries them.

netsh int ipv4 show excludedportrange protocol=tcp
netsh int ipv4 show excludedportrange protocol=udp
⚠ warningReserved ranges move after a reboot. If a port works on Monday and fails on Tuesday, this table is the first place to look.
05

Free the port the right way

Stop the service when there is one; killing the process only works until its watchdog restarts it. Reserve the fact that PID 4 is the kernel — http.sys holds those ports for other services.

Get-CimInstance Win32_Service | Where-Object { $_.Name -match 'MyApp' } | Select-Object Name,State
Stop-Service -Name MyApp -Force
net stop winnat
net start winnat
tipRestarting **winnat** releases the NAT reservations that block a port. It briefly interrupts container and VM networking.
06

Verify the port is actually free

Listen on it from PowerShell instead of starting the whole application. A successful bind is proof; a connection refusal proves nothing.

$l = [System.Net.Sockets.TcpListener]::new([System.Net.IPAddress]::Any, 8080)
$l.Start(); $l.Stop(); 'port free'
Test-NetConnection localhost -Port 8080 -InformationLevel Quiet
Troubleshooting

Common issues

The PID belongs to SYSTEM (4)

A kernel driver or the HTTP stack holds it. Query with netsh http show servicestate to see which registered URL uses the port, then reconfigure that service.

The port is free but the app still fails

Either the app lacks permission for a port below 1024 in that context, or the exclusion table blocks it. Check both, and test a port above 8000.

The process comes back after killing it

A service, a scheduled task or a watchdog restarts it. Disable the parent or change its configuration; killing is not a fix.

netstat shows no owner

You are not elevated, or the connection is in a state without a live process. Run as administrator and check TIME_WAIT entries separately.

FAQ

Frequently asked

Is it safe to kill the process?

For a stray dev server, yes. For anything running as a service, stop the service so its state is written correctly.

Why does a restart free the port?

TIME_WAIT entries expire and dynamic reservations are recalculated at boot. A port that frees itself after a restart was never held by a program.

How to undo this

Nothing to undo. Start the service you stopped with Start-Service, and if you restarted winnat, the containers or VMs reconnect on their own.

Changelog · 1 entry
  1. 2026-10-31
    First version
Interactive version: checklist, feedback, related guides →

Free · no account needed · tracks your progress