Domain 1Network FundamentalsCORE

TCP and UDP Transport Protocols

Comparison of TCP and UDP at the transport layer, covering the three-way handshake, reliability, flow control, and well-known port numbers.

Domain: Domain 1: Network Fundamentals•Updated: 2026-08-26
#TCP#UDP#Transport Layer#Three-Way Handshake#Port Numbers

Layer 4 Protocols: TCP and UDP

Layer 4 Overview

  • Concept: Layer 4 (Transport Layer) provides transparent transfer of data between end hosts and determines whether to provide various reliability services to applications.
  • Key Functions:
    • Transparent Data Transfer: Encapsulates data with a Layer 4 header and uses lower layers (3, 2, and 1) to deliver the data unchanged to the destination host. The hosts are unaware of the underlying network details.
    • Application Services: Provides reliable data transfer, error recovery, data sequencing, and flow control (provided by TCP, but not UDP).
    • Layer 4 Addressing: Uses port numbers to identify Application Layer protocols and provide session multiplexing (tracking multiple simultaneous communication sessions).

Port Numbers

  • Concept: 16-bit numbers (2 bytes) used for Layer 4 addressing. Because they are 16 bits, there are $2^{16}$ (65,536) available port numbers.
  • Port Ranges (IANA Designations):
    • Well-known ports: 0 - 1023 (Used for major protocols like HTTP, FTP; strictly regulated).
    • Registered ports: 1024 - 49151 (Registration is required, but less strictly regulated).
    • Ephemeral (Dynamic/Private) ports: 49152 - 65535 (Used by hosts to randomly select source ports for sessions).
  • Session Multiplexing:
    • Source Port: Randomly selected from the ephemeral range. Identifies the specific session on the client.
    • Destination Port: Identifies the Application Layer protocol/service on the server (e.g., port 80 for HTTP).
    • When a server replies, it reverses the source and destination ports so the client can match the reply to the correct session.
  • Things to note: A Layer 4 “port” is a logical software construct (port number), which is completely different from a physical switch/router “port” (physical interface).

Transmission Control Protocol (TCP)

  • Concept: A connection-oriented protocol that provides reliable, sequenced, and flow-controlled data transfer.
  • Key Features:
    • Connection-Oriented: Establishes a connection before sending data using a Three-Way Handshake.
    • Reliable Communication: The destination must acknowledge (ACK) each segment. If the source does not receive an ACK, it retransmits the segment.
    • Sequencing: Uses sequence numbers to reassemble segments in the correct order if they arrive out of sequence. Uses forward acknowledgment (the ACK number indicates the next expected sequence number, not the one just received).
    • Flow Control: Uses a sliding window mechanism (Window Size field) to dynamically adjust the rate of data transmission so the receiver is not overwhelmed.
  • TCP Header Fields:
    • Source/Destination Ports: 16 bits each.
    • Sequence Number: Tracks the order of segments.
    • Acknowledgment Number: Indicates the next expected sequence number.
    • Flags: Control bits used for connection management. Key flags: SYN (Synchronize), ACK (Acknowledgment), FIN (Finish).
    • Window Size: Used for flow control.
  • Connection Establishment (Three-Way Handshake):
    1. Client sends SYN (Initial Sequence Number = random, e.g., 10).
    2. Server replies with SYN-ACK (Initial Sequence Number = random, e.g., 50; Acknowledgment = 11).
    3. Client sends ACK (Sequence Number = 11; Acknowledgment = 51).
  • Connection Termination (Four-Way Handshake):
    1. Client sends FIN.
    2. Server replies with ACK.
    3. Server sends FIN.
    4. Client replies with ACK.
sequenceDiagram
    participant Client
    participant Server
    Note over Client,Server: Three-Way Handshake (Establishment)
    Client->>Server: SYN (Seq=x)
    Server->>Client: SYN-ACK (Seq=y, Ack=x+1)
    Client->>Server: ACK (Seq=x+1, Ack=y+1)
    Note over Client,Server: Connection Established
    Note over Client,Server: Four-Way Handshake (Termination)
    Client->>Server: FIN
    Server->>Client: ACK
    Server->>Client: FIN
    Client->>Server: ACK

User Datagram Protocol (UDP)

  • Concept: A connectionless, “best-effort” protocol with minimal overhead.
  • Key Features:
    • Connectionless: No handshake is performed; data is sent immediately.
    • Unreliable (Best-Effort): No acknowledgments are sent, and there are no retransmissions if segments are lost.
    • No Sequencing: No mechanism exists to reorder segments if they arrive out of order.
    • No Flow Control: No mechanism exists to throttle data transmission rates.
  • UDP Header Fields:
    • Source Port
    • Destination Port
    • Length: Indicates the length of the UDP segment.
    • Checksum: Allows the receiving host to check for errors.

TCP vs. UDP Comparison

Feature TCP UDP
Connection Type Connection-oriented (Handshake) Connectionless
Reliability Reliable (ACKs, Retransmissions) Unreliable / Best-effort
Sequencing Yes (Reorders segments) No
Flow Control Yes (Sliding Window) No
Header Overhead High (Larger header) Low (Smaller header)
Speed/Delay Slower (Due to overhead/ACKs) Faster / Delay-sensitive
Use Cases Web browsing, Email, File Transfers VoIP, Video streaming, DNS, DHCP

Well-Known Port Numbers

Things to note: Memorize these port numbers and whether they use TCP or UDP. DNS is the only protocol listed that uses both TCP and UDP (typically UDP, but uses TCP for zone transfers or large responses). While UDP itself is unreliable, some applications (like TFTP or Skype) build their own reliability mechanisms on top of UDP.

TCP Protocols

Protocol Description Port(s)
FTP File Transfer Protocol 20 (Data), 21 (Control)
SSH Secure Shell (Secure CLI access) 22
Telnet Unsecure CLI access 23
SMTP Simple Mail Transfer Protocol (Sending email) 25
HTTP Hypertext Transfer Protocol (Web pages) 80
POP3 Post Office Protocol v3 (Retrieving email) 110
HTTPS HTTP Secure (Encrypted web traffic) 443

UDP Protocols

Protocol Description Port(s)
DHCP Dynamic Host Configuration Protocol 67 (Server), 68 (Client)
TFTP Trivial File Transfer Protocol 69
SNMP Simple Network Management Protocol 161 (Traffic), 162 (Traps)
Syslog Log message standard 514

Both TCP & UDP

Protocol Description Port(s)
DNS Domain Name System 53 (Usually UDP, TCP for large transfers)

Common Misconceptions & Exam Tips

  • Forward Acknowledgment: In TCP, if a host receives sequence number 27, it acknowledges it by sending an ACK for 28 (the next expected segment), not 27. If it sent 27, the sender would assume the segment was lost and retransmit it.
  • Random Source Ports: When a client initiates a connection, the destination port is fixed based on the service (e.g., 80 for HTTP), but the source port must be randomly selected from the Ephemeral range (49152 - 65535).
  • TCP Window Size: Acknowledging every single segment is inefficient. The Window Size field allows multiple segments to be sent before an acknowledgment is required. The window dynamically shrinks if packets are dropped and slowly expands again.

Quick Reference Summary

(Since this transcript focuses on Layer 4 theory rather than IOS CLI configuration, the “commands” summary below lists the critical port numbers and protocols you must memorize for the exam).

TCP Ports:

  • 20/21 (FTP), 22 (SSH), 23 (Telnet), 25 (SMTP), 80 (HTTP), 110 (POP3), 443 (HTTPS)

UDP Ports:

  • 67/68 (DHCP), 69 (TFTP), 161/162 (SNMP), 514 (Syslog)

TCP & UDP:

  • 53 (DNS)