The transport layer provides logical communication between application processes running on different hosts. This is a crucial distinction from the network layer, which provides logical communication between hosts themselves.
Think of the transport layer as the postal service within a household. The network layer (like the national postal service) delivers mail to houses, but the transport layer distributes letters to specific people (processes) within each house. Just as multiple family members can receive mail at the same address, multiple processes can receive data on the same host.
| Aspect | Network Layer | Transport Layer |
|---|---|---|
| Communication Level | Host-to-host (logical) | Process-to-process (logical) |
| Primary Function | Routing packets between hosts | Delivering data to correct application |
| Addressing | IP addresses | Port numbers |
| Reliability | Best-effort (unreliable) | Can be reliable (TCP) or unreliable (UDP) |
| Example Protocols | IP, ICMP | TCP, UDP |
Understanding the transport layer requires mastering these interconnected topics:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β APPLICATION LAYER β
β Process A (Port 80) Process B (Port 443) β
ββββββββββ¬ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β β
β Socket β Socket
β β
ββββββββββΌββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β TRANSPORT LAYER (Multiplexing) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β TCP Segment β β TCP Segment β β UDP Datagram β β
β β Src: 12345 β β Src: 54321 β β Src: 9999 β β
β β Dst: 80 β β Dst: 443 β β Dst: 53 β β
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββ¬ββββββββ β
βββββββββββΌβββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββ
β β β
ββββββββββββββββββββ΄βββββββββββββββββββ
β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ
β NETWORK LAYER (IP) β
β Routes to destination host β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Multiplexing (sender): Gathering data from multiple sockets, adding transport headers, passing segments to network layer.
Demultiplexing (receiver): Using header information to deliver segments to the correct socket.
UDP (User Datagram Protocol) is the simplest transport protocol, providing minimal services beyond multiplexing/demultiplexing.
0 16 31 ββββββββββββββββββββββ¬βββββββββββββββββββββ β Source Port β Destination Port β (16 bits each) ββββββββββββββββββββββΌβββββββββββββββββββββ€ β Length β Checksum β (16 bits each) ββββββββββββββββββββββ΄βββββββββββββββββββββ€ β β β Application Data β β (payload) β β β βββββββββββββββββββββββββββββββββββββββββββ Length: Total length of UDP segment (header + data) Checksum: Error detection (optional in IPv4, mandatory in IPv6)
Building a reliable protocol over an unreliable channel requires addressing three main problems:
Solution: Error detection (checksums) + acknowledgments (ACKs) + retransmissions
Solution: Timeouts + retransmissions
Solution: Pipelining (send multiple packets before waiting for ACK)
| Protocol | Go-Back-N (GBN) | Selective Repeat (SR) |
|---|---|---|
| Window | Sender can have N unacked packets | Sender can have N unacked packets |
| ACK Type | Cumulative (ACK n = all up to n received) | Individual (ACK n = only n received) |
| Retransmission | Retransmit all from lost packet onward | Retransmit only lost packet |
| Receiver Buffer | No buffering of out-of-order packets | Buffers out-of-order packets |
| Used By | Simpler, less common | TCP (modified version) |
TCP (Transmission Control Protocol) provides reliable, ordered, connection-oriented communication between processes.
0 16 31 ββββββββββββββββββββββ¬βββββββββββββββββββββ β Source Port β Destination Port β ββββββββββββββββββββββ΄βββββββββββββββββββββ€ β Sequence Number β (32 bits) βββββββββββββββββββββββββββββββββββββββββββ€ β Acknowledgment Number β (32 bits) βββββββ¬ββββ¬ββββββββββ¬ββββββββββββββββββββββ€ βHdr βResβ Flags β Window Size β βLen β βUAPRSF β (flow control) β βββββββ΄ββββ΄ββββββββββΌββββββββββββββββββββββ€ β Checksum β Urgent Pointer β βββββββββββββββββββββ΄ββββββββββββββββββββββ€ β Options (if any) β βββββββββββββββββββββββββββββββββββββββββββ€ β β β Application Data β β β βββββββββββββββββββββββββββββββββββββββββββ Key Fields: - Sequence Number: Byte number of first data byte - ACK Number: Next expected byte from other side - Flags: URG, ACK, PSH, RST, SYN, FIN - Window Size: Bytes willing to accept (flow control) - Checksum: Error detection (mandatory)
TCP sequence numbers work like page numbers in a book. If you're sending a 1000-byte file starting at sequence number 0, the first segment might contain bytes 0-499 (seq=0), the second bytes 500-999 (seq=500). The ACK number is like saying "I've read up to page 500, send me page 500 next."
TCP uses an adaptive timeout based on RTT (Round-Trip Time) measurements:
If sender receives 3 duplicate ACKs for same data, it retransmits the segment before the timer expires.
Flow control prevents the sender from overwhelming the receiver's buffer.
rwnd (receive window) fieldrwndReceiver Buffer: βββββββββββββββββββββββββββββββββββββββββββ β [Data read by app] β [Free space=rwnd] β βββββββββββββββββββββββββββββββββββββββββββ Sender must ensure: LastByteSent - LastByteAcked β€ rwnd
Client Server β β β SYN (seq=100) β ββββββββββββββββββββββββββββββ>β β β β SYN-ACK (seq=300, ack=101) β β<ββββββββββββββββββββββββββββββ β β β ACK (seq=101, ack=301) β ββββββββββββββββββββββββββββββ>β β β β Connection Established β β<ββββββββββββββββββββββββββββ>β
The 3-way handshake is like making a phone call: (1) You dial and say "Hello?" (SYN), (2) They answer "Hello, I hear you!" (SYN-ACK), (3) You confirm "Great, I hear you too!" (ACK). Now both parties know the connection works both ways.
Congestion control prevents the sender from overwhelming the network.
cwnd = 1 MSS (Maximum Segment Size)cwnd += 1 MSScwnd β₯ ssthresh or loss detectedcwnd β₯ ssthresh, enter congestion avoidancecwnd += MSS Γ (MSS/cwnd)| Loss Indication | Action | Interpretation |
|---|---|---|
| Timeout | ssthresh = cwnd/2 cwnd = 1 MSS Enter slow start |
Severe congestion |
| 3 Duplicate ACKs | ssthresh = cwnd/2 cwnd = ssthresh + 3 MSS Fast recovery |
Mild congestion |
The core principle of TCP congestion control:
cwnd (MSS)
β
24 β β±β²
β β± β²
16 β β±β²β± β²
β β± β²β±β²
8 β β± β²
β β± β²
1 ββ± β²
βββββββββββββββββββββββββ> Time (RTT)
β β β β β
SS CA Loss CA Loss
SS = Slow Start (exponential)
CA = Congestion Avoidance (linear)
Loss = Multiplicative decrease
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (handshake) | Connectionless |
| Reliability | Reliable (ACKs, retransmissions) | Unreliable (best-effort) |
| Ordering | In-order delivery guaranteed | No ordering guarantee |
| Flow Control | Yes (receive window) | No |
| Congestion Control | Yes (cwnd, AIMD) | No |
| Header Size | 20-60 bytes | 8 bytes |
| Speed | Slower (overhead) | Faster (minimal overhead) |
| Use Cases | HTTP, FTP, email, SSH | DNS, VoIP, streaming, gaming |
Host A sends a TCP segment to Host B with sequence number 500 and 200 bytes of data. Host B's next acknowledgment number will be:
(a) 500 (b) 501 (c) 699 (d) 700
Given EstimatedRTT = 100ms, DevRTT = 20ms, calculate the TimeoutInterval.
A TCP connection starts with cwnd = 1 MSS. After 4 RTTs in slow start (no losses), what is cwnd?
(a) 4 MSS (b) 8 MSS (c) 16 MSS (d) 32 MSS
Which fields does UDP use to demultiplex segments to the correct socket?
(a) Source IP only
(b) Destination port only
(c) Destination IP and destination port
(d) Source IP, source port, destination IP, destination port
In a TCP three-way handshake, the client sends SYN with seq=1000. The server responds with SYN-ACK with seq=5000. What should the client's ACK segment contain?
TCP is in congestion avoidance with cwnd = 24 MSS and ssthresh = 16 MSS. A timeout occurs. What are the new values?
A receiver has a buffer size of 4000 bytes. It has 1500 bytes of data waiting to be read by the application. What rwnd value does it advertise?
A sender receives the following ACKs: 100, 100, 100, 100. What should the sender do?
Why does UDP include a checksum if it's an unreliable protocol?
Two TCP connections share a bottleneck link. Connection A has cwnd = 8 MSS, Connection B has cwnd = 4 MSS. After one RTT with no loss, what are the new cwnd values? How does this demonstrate fairness?
When solving TCP problems, always draw a timeline diagram showing segments, ACKs, and time progression. This visual approach prevents errors in sequence number calculations and helps you track connection states during handshakes and teardowns.
The transport layer bridges the gap between application processes and the network, providing essential services:
Understanding these mechanisms deeplyβnot just memorizing formulasβis key to mastering computer networks and excelling in exams.
β Back to Blog