Online admissions open for the SEO, web development and networking & cybersecurity courses. Enquire for the next batch.

Network Ports and Protocols: TCP, UDP and Common Ports

5 min read Updated By the SkillNewton team

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:443 or [2001:db8::20]:443 for 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.

AspectTCPUDP
SetupThree-way handshake before dataNo setup; first datagram carries data
DeliveryReliable, ordered, retransmits lossesNo acknowledgement, ordering or retransmission
Port state seen in scansOpen, closed or filtered is usually clearHarder to tell, because closed and filtered can look alike
ExamplesHTTPS, SSH, SMTP, RDP, databasesDNS 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

RangeNameUse
0 to 1023Well-known (system) portsCore services such as SSH, DNS, HTTP and HTTPS; assigned by IANA
1024 to 49151Registered (user) portsApplications registered with IANA, such as MySQL on 3306 and RDP on 3389
49152 to 65535Dynamic or private portsNever 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

PortTransportServiceNote
20, 21TCPFTP data and controlPlain text; prefer SFTP
22TCPSSH, SFTPEncrypted remote access and file transfer
23TCPTelnetPlain text; disable on devices
25TCPSMTPServer-to-server mail
53UDP, TCPDNSTCP for large answers and zone transfers
67, 68UDPDHCP server, clientAddress assignment
69UDPTFTPDevice firmware and boot files
80TCPHTTPUsually redirects to HTTPS
110, 995TCPPOP3, POP3SMail download
123UDPNTPTime synchronisation
143, 993TCPIMAP, IMAPSMailbox access
161, 162UDPSNMP, SNMP trapsMonitoring; use SNMPv3
389, 636TCPLDAP, LDAPSDirectory services
443TCP, UDPHTTPS, HTTP/3 (QUIC)Encrypted web
445TCPSMBWindows file sharing; never expose to the internet
465, 587TCPSMTP submissionMail clients sending through a server
514UDPSyslogLog forwarding
853TCPDNS over TLSEncrypted DNS
1433TCPMicrosoft SQL ServerDatabase
3306TCPMySQL, MariaDBDatabase
3389TCP, UDPRDPPut behind a VPN
5432TCPPostgreSQLDatabase
8080TCPHTTP alternativeProxies 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 test

Read 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.

  1. List what is listening with ss -tulpn and remove or stop services nobody needs.
  2. Bind internal services such as databases to 127.0.0.1 or a private interface rather than every address.
  3. Apply default-deny firewall rules that open only the ports each server needs, as explained in how firewalls work.
  4. Replace plain-text protocols such as Telnet, FTP and unencrypted LDAP with SSH, SFTP and LDAPS.
  5. 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.

  1. Run ss -tulpn and record every listening port, its protocol, the bound address and the process name.
  2. For each port, note the expected service and whether it should be reachable from other machines.
  3. Start python3 -m http.server 8000, confirm it appears in the list, then stop it and confirm it disappears.
  4. Browse a website, then run ss -tn state established and identify your ephemeral source ports and the remote port.
  5. 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.0 when 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.

Want to Learn This Properly?

The Networking & Cybersecurity: Foundation & Practical Implementation (Online) turns guides like this into practised skills, with projects on real websites.

WhatsApp Call Us Now

Free counselling

Send an Enquiry

Tell us which course you are interested in. We reply by email or phone with the next batch and how to enrol.

Protected by reCAPTCHA. Google Privacy and Terms apply.

We reply by email or phone within working hours. No spam.