Network Ports and Protocols: TCP, UDP and Common Ports
What is a network port?
A port is a 16-bit number from 0 to 65535 that identifies a specific service or connection on a host. The IP address gets a packet to the right device and the port gets it to the right program, such as a web server on TCP 443. Ports exist separately for TCP and UDP, and IANA divides them into well-known, registered and dynamic ranges.
Ports, protocols and sockets
A single server may run a web server, SSH and DNS at once. All three share one IP address, so the transport layer uses port numbers to tell their traffic apart. A protocol such as HTTP or SSH defines the conversation; a port is simply where a service listens for it.
- Socket: an IP address plus a port and transport protocol, written as
192.168.1.20:443or[2001:db8::20]:443for IPv6. - Listening socket: a server waiting for connections on a port.
- Connection: identified by the five-tuple of protocol, source IP, source port, destination IP and destination port.
- Ephemeral port: a temporary port that the client operating system picks for its end of a connection.
When your browser opens a page, the connection might be 192.168.1.50:51734 to 203.0.113.10:443. Open a second tab to the same site and the client simply picks another ephemeral port, so the two connections stay separate.
TCP and UDP ports
TCP port 53 and UDP port 53 are different ports, even though DNS uses both. A firewall rule must name the protocol as well as the number.
| Aspect | TCP | UDP |
|---|---|---|
| Setup | Three-way handshake before data | No setup; first datagram carries data |
| Delivery | Reliable, ordered, retransmits losses | No acknowledgement, ordering or retransmission |
| Port state seen in scans | Open, closed or filtered is usually clear | Harder to tell, because closed and filtered can look alike |
| Examples | HTTPS, SSH, SMTP, RDP, databases | DNS queries, DHCP, NTP, SNMP, QUIC, VoIP media |
The handshake and flags are covered in the TCP/IP guide. For port work, remember that a TCP service either completes the handshake or refuses it, while a UDP service may stay silent unless the request is valid.
The three port ranges
| Range | Name | Use |
|---|---|---|
| 0 to 1023 | Well-known (system) ports | Core services such as SSH, DNS, HTTP and HTTPS; assigned by IANA |
| 1024 to 49151 | Registered (user) ports | Applications registered with IANA, such as MySQL on 3306 and RDP on 3389 |
| 49152 to 65535 | Dynamic or private ports | Never assigned; used for ephemeral client ports |
Operating systems choose their own ephemeral ranges. Windows uses 49152 to 65535, while Linux defaults to 32768 to 60999, which you can check with sysctl net.ipv4.ip_local_port_range. On Linux, binding a port below 1024 needs root or the CAP_NET_BIND_SERVICE capability, which is why many services start as root and then drop privileges.
Common ports to know
| Port | Transport | Service | Note |
|---|---|---|---|
| 20, 21 | TCP | FTP data and control | Plain text; prefer SFTP |
| 22 | TCP | SSH, SFTP | Encrypted remote access and file transfer |
| 23 | TCP | Telnet | Plain text; disable on devices |
| 25 | TCP | SMTP | Server-to-server mail |
| 53 | UDP, TCP | DNS | TCP for large answers and zone transfers |
| 67, 68 | UDP | DHCP server, client | Address assignment |
| 69 | UDP | TFTP | Device firmware and boot files |
| 80 | TCP | HTTP | Usually redirects to HTTPS |
| 110, 995 | TCP | POP3, POP3S | Mail download |
| 123 | UDP | NTP | Time synchronisation |
| 143, 993 | TCP | IMAP, IMAPS | Mailbox access |
| 161, 162 | UDP | SNMP, SNMP traps | Monitoring; use SNMPv3 |
| 389, 636 | TCP | LDAP, LDAPS | Directory services |
| 443 | TCP, UDP | HTTPS, HTTP/3 (QUIC) | Encrypted web |
| 445 | TCP | SMB | Windows file sharing; never expose to the internet |
| 465, 587 | TCP | SMTP submission | Mail clients sending through a server |
| 514 | UDP | Syslog | Log forwarding |
| 853 | TCP | DNS over TLS | Encrypted DNS |
| 1433 | TCP | Microsoft SQL Server | Database |
| 3306 | TCP | MySQL, MariaDB | Database |
| 3389 | TCP, UDP | RDP | Put behind a VPN |
| 5432 | TCP | PostgreSQL | Database |
| 8080 | TCP | HTTP alternative | Proxies and development servers |
Checking ports with ss and netstat
Start a small web server and then find it in the socket list. This works on any Linux machine with Python installed.
python3 -m http.server 8000 & # start a test web server on TCP 8000
ss -tlnp # listening TCP sockets with process names
ss -ulnp # listening UDP sockets
ss -tn state established # active TCP connections
sudo lsof -i :8000 # which process owns port 8000
grep -w 22/tcp /etc/services # the name the system maps to a port
kill %1 # stop the test server
netstat -ano | findstr :443 # Windows: connections on 443 with PIDs
Test-NetConnection example.com -Port 443 # Windows PowerShell reachability testRead the local address column carefully. 0.0.0.0:8000 or [::]:8000 means the service accepts connections on every interface, while 127.0.0.1:8000 means only the machine itself can connect. For more on these tools see networking on Linux.
Ports and security
Every listening port is part of a system's attack surface. Defenders keep that surface small and visible.
- List what is listening with
ss -tulpnand remove or stop services nobody needs. - Bind internal services such as databases to
127.0.0.1or a private interface rather than every address. - Apply default-deny firewall rules that open only the ports each server needs, as explained in how firewalls work.
- Replace plain-text protocols such as Telnet, FTP and unencrypted LDAP with SSH, SFTP and LDAPS.
- Scan your own systems periodically with a tool such as Nmap, only within the scope you are authorised to test, and compare the results with what you expect.
Practical exercise: build a port inventory
Use a Linux virtual machine or laptop that you own.
- Run
ss -tulpnand record every listening port, its protocol, the bound address and the process name. - For each port, note the expected service and whether it should be reachable from other machines.
- Start
python3 -m http.server 8000, confirm it appears in the list, then stop it and confirm it disappears. - Browse a website, then run
ss -tn state establishedand identify your ephemeral source ports and the remote port. - Check your ephemeral range with
sysctl net.ipv4.ip_local_port_range.
You are done when every listening port has a reason to exist or has been turned off. Service hardening of this kind is practised in the Networking Foundation course.
Common mistakes
- Opening a port in the firewall for TCP when the service uses UDP, or the reverse.
- Assuming a service is safe because it runs on an unusual port number.
- Leaving databases listening on
0.0.0.0when only the local application needs them. - Allowing DNS on UDP 53 but blocking TCP 53, which breaks large responses.
- Exposing RDP or SMB directly to the internet instead of placing them behind a VPN.
Frequently asked questions
How many ports are there?
There are 65,536 port numbers, 0 to 65535, for TCP and another 65,536 for UDP. Port 0 is reserved and is not used for normal services.
Can two programs listen on the same port?
Not on the same address and protocol in the usual case. They can share a number if one uses TCP and the other UDP, or if they bind to different IP addresses.
Is port scanning legal?
Scan only systems you own or have written permission to test. Unauthorised scanning can breach laws and acceptable use policies; see penetration testing explained for how authorised testing is scoped.
Why does HTTPS appear on UDP 443?
HTTP/3 runs over QUIC, which uses UDP. Browsers fall back to TCP 443 if UDP is blocked.