TCP and UDP

Transport layer: which application gets the data

IP gets a packet to the right device. The transport layer, TCP or UDP, gets it to the right application on that device, using port numbers. A web server listens on port 443; your browser uses a random high port (like 51234) as its source.

TCPUDP
ConnectionSet up first (three-way handshake)None: just send
ReliableYes: numbered segments, acknowledgements, resends what was lostNo: lost is lost
OrderPuts segments back in orderNo ordering
Flow controlYes (window size)No
Header20 bytes or more8 bytes
Good forWeb, email, file transfer, SSHVoice, video, DNS lookups, DHCP, syslog, SNMP

The three-way handshake

  1. Client → server: SYN ("let's talk; my first sequence number is X").
  2. Server → client: SYN-ACK ("OK; mine is Y, and I expect X+1 next").
  3. Client → server: ACK ("I expect Y+1"). Data can flow.

A connection ends with FIN and ACK from each side (or a RST to abort). Windowing lets the sender transmit several segments before waiting for an acknowledgement, and the receiver changes the window size to slow the sender down when it's busy.

Port numbers to know

PortProtocolTransport
20, 21FTP data, controlTCP
22SSH, SCP, SFTPTCP
23TelnetTCP
25SMTP (email)TCP
53DNSUDP (TCP for big answers and zone transfers)
67, 68DHCP server, clientUDP
69TFTPUDP
80, 443HTTP, HTTPSTCP (HTTP/3 uses UDP 443)
123NTPUDP
161, 162SNMP, SNMP trapsUDP
514SyslogUDP
49 / 1812, 1813TACACS+ / RADIUSTCP / UDP

Remember: Ports 0-1023 are well-known (servers), 1024-49151 registered, 49152-65535 dynamic (clients pick their source port here).

Tip: Real-time traffic uses UDP because a late voice sample is useless: resending it would only add delay. The application copes with a little loss instead.

HOME LABS COMMUNITY DASHBOARD