Diagram comparing TCP and UDP with the three-way handshake and common port numbers
Category: Network+ course

An IP address gets a packet to the right device, but every server runs dozens of services. Whether the packet reaches the web server or the email service is layer 4's job: the TCP and UDP protocols and port numbers.

What is a port?

A port is a number from 0 to 65535 that identifies a service on a device. If the IP is the building's address, the port is the flat number. The combination of IP and port, such as 192.168.1.10:443, is called a socket.

  • 0 to 1023: well-known ports, such as 80 and 443.
  • 1024 to 49151: registered ports for software, such as 3389.
  • 49152 and up: ephemeral ports the client picks for each connection.

TCP: reliable and ordered

TCP sets up a connection before sending, using the three-way handshake:

  1. The client sends SYN: "I want to connect."
  2. The server replies SYN-ACK: "Agreed, are you ready too?"
  3. The client sends ACK, and the connection is established.

After that, TCP numbers the data, gets an acknowledgement for each part and resends anything lost. That is why the web, email, file transfer and SSH run over TCP, where not a single byte can go missing.

UDP: fast and no-frills

UDP doesn't set up a connection or wait for acknowledgements; it just sends. It has less overhead and is faster. It suits work where delay is worse than losing a few packets:

  • Voice and video calls (VoIP audio with RTP)
  • DNS, which is one short question and one short answer
  • DHCP, live streaming and online games

In a VoIP call, resending a lost packet is pointless; that moment of audio has already passed.

FeatureTCPUDP
ConnectionConnection-oriented (handshake)Connectionless
ReliabilityAcknowledgements and retransmissionNone
OrderPackets arrive in orderNot guaranteed
Speed and overheadSlower, more overheadFaster, low overhead
ExamplesHTTP, SSH, SMTPDNS, DHCP, VoIP

Important ports to memorise

PortProtocolUse
20 and 21TCPFTP, file transfer
22TCPSSH and SFTP, secure management
23TCPTelnet, insecure management; don't use it
25TCPSMTP, sending email
53UDP and TCPDNS
67 and 68UDPDHCP
69UDPTFTP, e.g. for VoIP phone configuration files
80TCPHTTP
110 and 143TCPPOP3 and IMAP, receiving email
123UDPNTP, time synchronisation
161 and 162UDPSNMP, monitoring
389 and 636TCPLDAP and LDAPS, Active Directory
443TCPHTTPS
445TCPSMB, Windows file sharing
3389TCPRDP, Remote Desktop
5060 and 5061UDP and TCPSIP, VoIP

How to check whether a port is open

In Windows PowerShell:

Test-NetConnection 192.168.1.10 -Port 3389
netstat -ano | findstr LISTENING

The first command tells you whether port 3389 on the server is reachable from this computer. The second shows which ports are listening for connections on this computer.

A security note: never open ports such as 3389 (RDP) and 23 (Telnet) directly to the internet. Use a VPN for remote access.

Network+ course parts

  1. The OSI and TCP/IP models made simple
  2. IP addresses, classes and subnetting
  3. Hub vs switch vs router
  4. TCP, UDP and important network ports
  5. How DNS and DHCP work
  6. Network cabling: Cat5e, Cat6, Cat6A and fibre
  • Network+
  • CompTIA Network+
  • TCP vs UDP
  • network ports
  • three-way handshake
  • protocols