What a port number is and why you need to know it

A port number is a number between 0 and 65535 that identifies which program on your computer is sending or receiving data over the internet. Think of it like an apartment number — your computer's address is like the building, and the port number tells the data which apartment (program) to go to. When you're troubleshooting a network problem, setting up a firewall, or trying to figure out why a program won't connect, you often need to know which port it's using.

Port numbers are divided into ranges. Ports 0 to 1023 are reserved for common services like email (port 25 for SMTP, port 110 for POP3) and web traffic (port 80 for HTTP, port 443 for HTTPS). Ports 1024 and above are available for other programs. When you check a port number, you're looking for which program is using it and whether it's actively listening for connections.

Key Takeaways

  • On Windows, use the Command Prompt with netstat -ano to see all active ports and which program is using each one.
  • On Mac or Linux, use Terminal with lsof -i or netstat to list ports and their associated programs.
  • The Process ID (PID) number shown in the results tells you which program owns the port — match it to the program name in your system's task manager or process list.
  • If a port shows as "LISTENING", the program is actively waiting for connections; "ESTABLISHED" means a connection is already active.

Checking ports on Windows using Command Prompt

Open Command Prompt by pressing Windows key + R, typing cmd, and pressing Enter. At the prompt, type netstat -ano and press Enter. This command shows every port your computer is using, the program's Process ID (PID), and the connection state.

The output will show columns for Protocol (TCP or UDP), Local Address (your computer's address and port), Foreign Address (where it's connecting to), State (LISTENING, ESTABLISHED, TIME_WAIT, etc.), and PID. Find the port number you're looking for in the Local Address column. The number after the colon is the port. For example, if you see 127.0.0.1:8080, the port is 8080.

Once you have the PID, open Task Manager by pressing Ctrl + Shift + Esc. Go to the Details tab, and look for the PID number in the rightmost column. The program name in that row is what's using the port. If you don't see a PID column, right-click the column headers and select "Select Columns", then check the PID box.

Checking ports on Mac using Terminal

Open Terminal (search for it in Spotlight or find it in Applications > Utilities). Type lsof -i and press Enter. This shows all programs with active network connections, including the port numbers they're using.

The output displays the program name in the first column, the PID in the second column, and the port number in the last column under "NAME". Look for the port you're interested in. If you want to see only a specific port, type lsof -i :8080 (replace 8080 with your port number) to filter the results.

If lsof doesn't work or you prefer another method, type netstat -an | grep LISTEN to see all ports currently listening for connections. This shows the port in the fourth column. The state column will show LISTEN if the program is actively waiting for a connection.

Checking ports on Linux using Terminal

Open Terminal and type netstat -tlnp to see all TCP ports listening for connections, along with the program name and PID. The -t flag shows TCP ports, -l shows only listening ports, -n shows port numbers instead of service names, and -p shows the program name.

If netstat is not installed, use ss -tlnp instead — it does the same thing on newer Linux systems. Look for your port number in the "Local Address" column. The program name appears at the end of the line after the PID.

To check a specific port, type netstat -tlnp | grep :8080 (replace 8080 with your port) to see only that port's information. This is faster when you already know which port you're looking for.

Understanding port states and what they mean

When you run these commands, you'll see different states next to each port. LISTENING means the program is actively waiting for incoming connections on that port. ESTABLISHED means a connection is already active — data is being sent or received right now. TIME_WAIT means a connection was recently closed but the system is still cleaning up. CLOSE_WAIT means the other side closed the connection, but your program hasn't fully closed its end yet.

If you're troubleshooting a program that won't connect, look for LISTENING or ESTABLISHED. If you see TIME_WAIT or CLOSE_WAIT for a port you need, wait a minute and check again — these states clear automatically. If a port shows LISTENING but your program still won't work, the program may be listening on the wrong network interface (like localhost instead of your actual network address).

What to do if a port is already in use

If you're trying to start a program and it says a port is already in use, use the steps above to find which program is using it. Once you know the program name and PID, you have three options: close the other program, change your program to use a different port, or change the other program to use a different port.

To close a program using a port on Windows, open Task Manager, find the program by its PID or name, right-click it, and select "End Task". On Mac or Linux, type kill [PID] in Terminal (replace [PID] with the actual number) to close the program. If the program won't close, try kill -9 [PID], but this is more forceful and should be a last resort.

Before closing anything, make sure you know what the program is. If it's a system service or something you don't recognize, search for its name online or ask in a technical forum before terminating it — closing the wrong thing can cause problems.

Checking ports without command-line tools

If you're uncomfortable using Command Prompt or Terminal, some graphical tools can show port information. On Windows, download and install TCPView (free from Microsoft's Sysinternals website). It shows all active ports and connections in a window you can click through, with program names already matched to ports.

On Mac, Network Radar and Netstat (a graphical app, not the command) are available in the App Store. On Linux, Zenmap (the graphical version of Nmap) can scan your computer's ports, though it's more commonly used for network scanning.

These tools do the same thing as the command-line methods but display the information in a window instead of text. They're useful if you find the command line confusing, but the built-in commands are faster once you know how to use them.

Frequently Asked Questions

Why does my program say a port is in use when nothing else is using it?

The port may still be in TIME_WAIT state from a recent connection. Wait 30 to 60 seconds and try again. If it persists, restart your computer — this clears all temporary port states. You can also try changing your program to use a different port number if the documentation shows how.

Is it safe to close a program using a port?

It depends on what the program is. If it's something you started yourself (like a web server or game), closing it is safe. If it's a Windows system service or something you don't recognize, search for its name first. Closing critical system services can cause your computer to malfunction.

What's the difference between TCP and UDP ports?

TCP is connection-based — it ensures data arrives in order and without loss, used for email and web browsing. UDP is connectionless and faster but doesn't may provide delivery, used for video calls and online games. A program can use the same port number for both TCP and UDP at the same time.

Can I see what data is being sent on a port?

Yes, but it requires more advanced tools like Wireshark, which captures and displays network traffic. These tools show you what data is moving across a port, but they have a learning curve. For most troubleshooting, knowing which program is using a port is enough.

Why do some ports require administrator access to use?

Ports 0 to 1023 are reserved for system services and require administrator or root access to prevent regular programs from impersonating critical services like email or web servers. If your program needs one of these ports, you'll need to run it as administrator (Windows) or with sudo (Mac/Linux).