A port number is a number from 0 to 65535 that tells a computer which program should receive a piece of network traffic. The IP address gets data to the right machine; the port gets it to the right program on that machine, such as port 443 for a web server using HTTPS or port 22 for SSH.
To see which ports programs on your computer are listening on right now, run netstat -an on Windows or ss -ltn on Linux.
What a port number actually is
Every TCP segment and UDP datagram carries two port numbers in its header: a source port and a destination port. RFC 9293, the current TCP specification, defines both fields as 16 bits wide. Sixteen bits can hold 216 = 65,536 different values, which is where the range 0 to 65535 comes from.
A port is not a physical thing. It is a label the operating system uses to hand incoming data to the right socket. When a web server starts, it asks the OS to listen on port 443. From then on, any packet that arrives for that machine with destination port 443 is delivered to the web server, while packets for port 22 go to the SSH server, and so on.
TCP and UDP keep separate port spaces. TCP port 53 and UDP port 53 are two different ports, and two different programs could hold them.
IP address vs port: an analogy that holds up
Think of the IP address as a building's street address and the port as the apartment number. The postal service (IP routing) only cares about the street address. Once the letter reaches the building, the apartment number decides who opens it. That is why addresses are often written with the port after a colon: 192.168.1.10:443, or with brackets for IPv6, [2001:db8::10]:443.
When you type https://example.com into a browser, you never type a port, because the browser fills in the default for the scheme: 443 for https and 80 for http. Typing https://example.com:8443/ overrides that and connects to port 8443 instead.
The three port ranges
RFC 6335 splits the 65,536 numbers into three ranges. The Internet Assigned Numbers Authority (IANA) keeps the official registry.
| Range | Name | Who assigns it | Typical use |
|---|---|---|---|
| 0 to 1023 | System Ports (well-known ports) | IANA, only through IETF Review or IESG Approval | Core protocols: 22 SSH, 25 SMTP, 53 DNS, 80 HTTP, 443 HTTPS |
| 1024 to 49151 | User Ports (registered ports) | IANA, on request | Applications and databases: 3306 MySQL, 5432 PostgreSQL, 3389 Remote Desktop |
| 49152 to 65535 | Dynamic Ports (private or ephemeral ports) | Never assigned | Temporary client-side ports picked by the OS |
Registration is a convention, not enforcement. Nothing stops a program from listening on any free port; the registry exists so that two protocols don't fight over the same default. For a list of the ports you are most likely to meet, see common port numbers and what uses them.
Source port vs destination port
A connection has a port on each end. The server listens on a fixed, known port. The client gets a temporary port, called an ephemeral port, that the OS picks automatically when the program connects.
When your browser connects to a web server, the packets look like this (example values):
Your computer 192.168.1.25 : 52814 (ephemeral source port)
Web server 203.0.113.10 : 443 (well-known destination port)
Replies come back with the two swapped: source port 443, destination port 52814. Because every tab and every connection gets its own ephemeral port, your computer can hold dozens of connections to the same server at once without mixing up the replies.
Which range the OS picks ephemeral ports from depends on the system:
- Windows (Vista and later): 49152 to 65535, matching the IANA dynamic range. Microsoft changed this from the older 1025 to 5000. Check it with
netsh int ipv4 show dynamicport tcp. - Linux: 32768 to 60999 by default, set by the
net.ipv4.ip_local_port_rangesysctl. Check it withcat /proc/sys/net/ipv4/ip_local_port_range.
Example output on Windows 11:
Protocol tcp Dynamic Port Range
---------------------------------
Start Port : 49152
Number of Ports : 16384
49152 plus 16384 ports ends at 65535, the top of the range.
Sockets: IP address plus port
An IP address combined with a port is called a socket address. RFC 9293 says "a connection is defined by a pair of sockets", so one TCP connection is identified by four values: local IP, local port, remote IP and remote port. Change any one of them and it is a different connection. This is how a single web server on port 443 can talk to thousands of clients at once: the server's half of the pair is the same for all of them, but every client's IP and port combination is different.
You can watch the OS pick an ephemeral port yourself. Binding to port 0 means "give me any free port":
python -c "import socket; s=socket.socket(); s.bind(('127.0.0.1', 0)); print(s.getsockname())"
Example output:
('127.0.0.1', 55846)
Why ports below 1024 need root on Linux
On Linux, binding a socket to a port below 1024 needs root or the CAP_NET_BIND_SERVICE capability, which the capabilities(7) man page describes as permission to "bind a socket to Internet domain privileged ports (port numbers less than 1024)". This is one reason development servers default to ports like 3000, 5000 or 8080: an ordinary user can open them without sudo. Windows does not restrict them the same way: as a check, an ordinary (non-administrator) user on Windows 11 could bind a Python socket to 127.0.0.1:1023 without an error.
How to see which ports are in use
On Windows, in Command Prompt or PowerShell:
netstat -ano | findstr LISTENING
Or the PowerShell way, which returns objects you can filter:
Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess
On Linux:
ss -ltnp
On macOS:
lsof -nP -iTCP -sTCP:LISTEN
A local address of 0.0.0.0 or [::] means the program accepts connections on every network interface; 127.0.0.1 or [::1] means it only accepts connections from the same machine. If a program fails to start because its port is taken, fixing "port already in use" walks through finding and stopping the process that holds it.
What "open", "closed" and "filtered" mean
- Open: a program is listening on the port and the firewall lets traffic through.
- Closed: nothing is listening. A TCP connection attempt gets an immediate reset, which shows up as
Connection refused(ECONNREFUSED). - Filtered: a firewall silently drops the traffic, so the client waits until it times out.
A port can only be "open" from the outside if both conditions hold: something is listening, and every firewall and router in the path allows it. On a home network, the router's NAT blocks unsolicited inbound connections unless you set up port forwarding.
Ports and the transport protocol
Port numbers belong to the transport layer, the same layer as TCP and UDP. Both protocols use the same 16-bit port fields, but they behave very differently once the packet arrives. TCP vs UDP covers which protocols use which, and why DNS falls back from UDP 53 to TCP 53 when a response is too large.
Frequently asked questions
- What is the highest port number?
- 65535. The TCP and UDP headers store each port in a 16-bit field, so the possible values run from 0 to 65535, which is 65,536 numbers in total.
- Is a port the same as an IP address?
- No. The IP address identifies a computer (more precisely, a network interface) on the network. The port identifies a program or service on that computer. You need both to reach a service, written as 192.168.1.10:443 for IPv4 or [2001:db8::10]:443 for IPv6.
- Are TCP port 53 and UDP port 53 the same port?
- No. TCP and UDP each have their own set of 65,536 ports, so a program can listen on TCP 53 while another listens on UDP 53. IANA usually registers a service on both protocols with the same number to avoid confusion, which is why DNS appears as 53 on both.
- Is it dangerous to have open ports?
- An open port is only as risky as the program listening on it. A port that is listening but blocked by a firewall cannot be reached from outside. Close or firewall anything you don't recognise, and keep the software behind any port you expose up to date.
Sources
- RFC 6335: IANA Procedures for the Management of the Service Name and Transport Protocol Port Number Registry
- RFC 9293: Transmission Control Protocol (TCP)
- IANA: Service Name and Transport Protocol Port Number Registry
- Microsoft Learn: The default dynamic port range for TCP/IP has changed
- Linux kernel documentation: IP sysctl (ip_local_port_range)
- Linux man-pages: capabilities(7)