By the end of this chapter you'll be able to…

  • 1Explain how UDP and TCP demultiplex differently and why a server port supports thousands of connections
  • 2List the TCP header fields and say which limitation each option was added to remove
  • 3Justify the three-way handshake by exhibiting the failure of a two-way exchange
  • 4Explain why release takes four steps and what TIME_WAIT protects against
  • 5Compute an adaptive timeout from round-trip samples with the standard weights
  • 6State Karn's algorithm and why sampling retransmitted segments is invalid
  • 7Distinguish flow control from congestion control and name the mechanism each uses
  • 8Explain silly window syndrome and both its receiver-side and sender-side fixes
  • 9Trace the congestion window through slow start, congestion avoidance, timeout and fast recovery
  • 10Contrast Tahoe with Reno on the response to three duplicate acknowledgements
  • 11Apply the throughput formula and explain the square-root dependence on loss
💡
Why this chapter matters in GATE
The transport layer turns host-to-host best effort into process-to-process service using nothing but header numbers and timers, so every mechanism is one of those two tools applied to a specific problem. GATE tests congestion window evolution across round trips, timeout estimation, the three-way handshake rationale, and the flow-versus-congestion control distinction.

Before you start — revise these

🔗
IP best-effort delivery and the network layer's lack of guarantees
🔗
Sliding window protocols from the data link layer
🔗
Bandwidth-delay product and round-trip time

The Transport Layer

The network layer delivers datagrams to a machine, unreliably and in any order. Applications want something quite different.

The organising fact is that the transport layer turns a host-to-host, best-effort service into a process-to-process service with whatever guarantees the application needs, and the only tools it has are numbers in a header and timers.

Port numbers give process-to-process delivery. Sequence numbers give ordering and duplicate detection. Acknowledgements plus timers give reliability. Window sizes give flow and congestion control.

Nothing else is available, because the layer runs only at the endpoints and cannot inspect or influence the network in between.

The second organising fact is that flow control and congestion control are different problems with similar mechanisms. Flow control protects the receiver from a fast sender. Congestion control protects the network from all senders together. TCP implements both with windows, and confusing them is a reliable way to lose marks.

The third is that TCP infers congestion from loss, because the network gives it no other signal. That inference is a design choice with consequences, notably on wireless links where loss is often corruption rather than congestion.

1. Multiplexing and Sockets

A port number identifies a process on a host, and the pair of an IP address and a port is a socket.

UDP demultiplexes on the destination port alone, so all datagrams to one port reach one socket regardless of sender.

TCP demultiplexes on all four values: source address, source port, destination address, destination port. That is why a server can hold thousands of connections on port 80, each a distinct socket.

Well-known ports run from 0 to 1023, registered ports to 49151, and the rest are ephemeral, assigned to clients temporarily.

A listening socket and a connected socket are different objects. The server's listening socket is identified by its own address and port alone, while each accepted connection creates a new socket identified by all four values.

2. UDP

UDP adds only four fields to IP: source port, destination port, length and checksum.

It offers no connection, no reliability, no ordering and no congestion control, and that minimalism is exactly why it is used.

The header is 8 bytes against TCP's 20, and there is no handshake, so a request and reply take one round trip instead of two.

The checksum is optional in IPv4 and mandatory in IPv6, and it covers a pseudo-header including the IP addresses, which lets the receiver detect misdelivery.

UDP suits applications that supply their own reliability or do not want any: DNS, DHCP, streaming media, online games, and anything where a late packet is worse than a lost one.

QUIC is the modern demonstration of this. It runs reliability, ordering and congestion control over UDP in user space, precisely so those mechanisms can evolve without waiting for operating system kernels to change.

3. TCP Connection Management

The header is 20 bytes without options and up to 60 with them.

The sequence number counts bytes, not segments, which is the fact most often needed in numerical questions.

The acknowledgement number is cumulative, naming the next byte expected, so one acknowledgement confirms everything before it.

Connection setup is a three-way handshake. The client sends SYN with its initial sequence number; the server replies with SYN and ACK carrying its own; the client acknowledges.

Two exchanges would not suffice, because both directions need their initial sequence numbers established and acknowledged, and a delayed duplicate SYN from an old connection could otherwise open a phantom connection.

Connection release takes four steps, since each direction closes independently: FIN, ACK, FIN, ACK.

The closing side then waits in TIME_WAIT for twice the maximum segment lifetime. This ensures the final acknowledgement arrives, and that no old segment from this connection can appear in a new one using the same port pair.

The TCP Header Fields

FieldSizePurpose
Source and destination port16 bits eachIdentify the two processes
Sequence number32 bitsByte offset of the first data byte
Acknowledgement number32 bitsNext byte expected, cumulative
Data offset4 bitsHeader length in 4-byte words
Flags6 bitsURG, ACK, PSH, RST, SYN, FIN
Window16 bitsReceiver's advertised buffer space
Checksum16 bitsCovers header, data and a pseudo-header
Urgent pointer16 bitsOffset of urgent data, rarely used

The 16-bit window field is the constraint that forced window scaling, since 65,535 bytes cannot fill any modern long-distance link.

RST aborts a connection immediately without the four-step release, and is what a host sends when a segment arrives for a port nobody is listening on.

PSH asks the receiver to deliver buffered data to the application at once rather than waiting for more, which is what makes interactive protocols responsive.

4. Reliability and Timers

A sender retransmits a segment when its timer expires, and choosing that timer is delicate. Too short causes needless retransmission; too long wastes time on real losses.

The round-trip time is estimated by exponential averaging.

with conventionally.

The variation is tracked separately as DevRTT with weight , and the timeout is

Including the deviation matters because a stable network deserves a tight timeout while a variable one needs slack, and a fixed multiplier of the mean cannot provide both.

Karn's algorithm forbids sampling the round-trip time from a retransmitted segment, because the acknowledgement might refer to either transmission and the sample would be meaningless. Timeouts are instead doubled on each retransmission.

Fast retransmit resends a segment after three duplicate acknowledgements without waiting for the timer, since three duplicates strongly suggest one segment was lost while later ones arrived.

5. Flow Control

The receiver advertises a window stating how much buffer space remains, and the sender never has more unacknowledged data outstanding than that.

This is flow control: protecting a slow receiver from a fast sender. It says nothing about the network.

Silly window syndrome occurs when the receiver advertises tiny windows as its application consumes a few bytes at a time, so the sender transmits many minimal segments with 40 bytes of header each.

Clark's solution is receiver-side: advertise zero until either half the buffer or one full segment is free.

Nagle's algorithm is the sender-side counterpart: while unacknowledged data is outstanding, buffer small writes and send them as one segment when the acknowledgement arrives.

Nagle interacts badly with delayed acknowledgements, since each waits for the other, producing a characteristic delay that interactive applications disable Nagle to avoid.

6. Congestion Control

TCP maintains a congestion window and sends the minimum of it and the receiver's advertised window.

Slow start begins with a congestion window of one segment and doubles it every round trip, which despite the name is exponential growth.

On reaching the slow start threshold, congestion avoidance takes over, increasing the window by one segment per round trip, which is linear.

The two phases together are additive increase, and the response to loss is multiplicative decrease.

A timeout is treated as severe congestion. The threshold is set to half the current window and the window drops to one segment, restarting slow start.

Three duplicate acknowledgements are treated as mild congestion, since segments are still getting through.

TCP Tahoe treats both the same, dropping to one segment in either case.

TCP Reno adds fast recovery: on three duplicate acknowledgements it halves the window and continues in congestion avoidance rather than restarting slow start.

The steady-state throughput of a long-lived connection is approximately for loss rate , which shows why long-distance connections with even slight loss perform poorly.

7. Worked Examples

Example 1. A TCP connection has a maximum segment size of 1 KB. The slow start threshold begins at 8 segments. Trace the congestion window over 12 round trips, with a timeout after the 6th and three duplicate acknowledgements after the 10th, under Reno.

Round 1: window is 1, slow start.

Round 2: doubles to 2. Round 3: 4. Round 4: 8.

The window has reached the threshold of 8, so congestion avoidance begins.

Round 5: 9, increasing linearly. Round 6: 10.

A timeout occurs after round 6.

The threshold becomes half the current window, that is 5, and the window drops to 1, restarting slow start.

Round 7: 1. Round 8: 2. Round 9: 4.

Round 10: doubling would give 8, but the threshold is 5, so the window becomes 5 and congestion avoidance resumes.

Three duplicate acknowledgements occur after round 10.

Under Reno, this is fast recovery: the threshold becomes half of 5, which rounds to 2, and the window becomes 2, continuing in congestion avoidance rather than restarting.

Round 11: 2. Round 12: 3.

Under Tahoe the outcome after round 10 would differ: the window would drop to 1 and slow start would restart, giving 1 then 2 for rounds 11 and 12.

The whole point of fast recovery is visible here. Reno reaches 3 where Tahoe reaches 2, because it recognises that segments still arriving mean the pipe is not empty.

Example 2. Successive round-trip samples are 100, 120, 90 and 110 milliseconds. Starting from an estimate of 100 and a deviation of 10, compute the timeout after all four samples with and .

Apply both recurrences per sample.

Sample 100: estimate becomes . Deviation becomes .

Sample 120: estimate becomes . Deviation uses the previous estimate, so , giving .

Sample 90: estimate becomes . Deviation uses , giving .

Sample 110: estimate becomes . Deviation uses , giving .

The timeout is milliseconds.

Note the safety margin. The timeout sits about 40 percent above the mean, which is what the deviation term buys: on a stable link the deviation would shrink and the timeout would tighten automatically.

Example 3. Why is a two-way handshake insufficient for TCP connection establishment?

Suppose the protocol were SYN followed by SYN-ACK, with data then flowing.

Consider a duplicate SYN from an old, closed connection that was delayed in the network and arrives late.

The server sees a connection request, allocates state, and replies with SYN-ACK.

The client is not opening a connection and discards the reply, but the server is now holding a half-open connection consuming resources.

Worse, if old data segments from that earlier connection also arrive, the server may accept them as belonging to this new connection, since their sequence numbers fall in the expected range.

The third message closes the hole. The server commits only after the client acknowledges the server's own initial sequence number.

A client that never sent the SYN will not acknowledge, so the server times out and releases the state.

The essential point is that each direction needs its sequence number both delivered and acknowledged, which requires three messages when one of them can be combined.

Randomising initial sequence numbers strengthens this further, making it improbable that an attacker or a stale segment guesses a valid number.

Example 4. A 10 Gbps link carries a TCP connection. How long before the 32-bit sequence number space wraps around, and why does that matter?

The sequence space is bytes, which is about 4.29 gigabytes.

At 10 gigabits per second, the byte rate is 1.25 gigabytes per second.

Wraparound time is seconds.

Why this matters: the maximum segment lifetime is conventionally taken as 2 minutes.

A segment delayed in the network for even a few seconds could reappear after the sequence numbers have wrapped, landing inside the current valid window and being accepted as new data.

The protection is the timestamp option, which adds a monotonically increasing value to each segment, so a segment from an earlier lap of the sequence space is recognised by its stale timestamp and discarded.

This is called protection against wrapped sequence numbers, and it is mandatory on any high-speed link.

Note how this compounds with window scaling. Both options exist because TCP's original 16-bit and 32-bit fields were sized for links thousands of times slower than today's.

Example 5. A connection has a round-trip time of 50 milliseconds, a maximum segment size of 1460 bytes and a loss rate of 0.01 percent. Estimate throughput, then recompute at 1 percent loss.

Use .

At : , so .

bytes per second, times 100 gives 2.92 megabytes per second, about 23 megabits per second.

At : , so .

Throughput becomes 292 kilobytes per second, about 2.3 megabits per second, a tenfold reduction.

A hundredfold increase in loss cost a tenfold drop in throughput, which is the square root relation made concrete.

The practical consequence is severe on long paths. Doubling the round-trip time halves the throughput regardless of available bandwidth, which is why a connection from India to the United States can crawl on a link with gigabits to spare.

This is also the argument for modern congestion control algorithms such as BBR, which estimate bandwidth and round-trip time directly rather than inferring congestion from loss.

Example 6. For each application, choose UDP or TCP and justify: a DNS query, a file transfer, a live video call, a bulk database replication.

A DNS query uses UDP. The request and response each fit in one datagram, so a handshake would triple the cost of the exchange, and the application simply retries on no answer.

Large DNS responses fall back to TCP, since UDP truncation forces it, which is why both are provisioned.

A file transfer uses TCP. Every byte must arrive and order matters, so building reliability into the application would mean reimplementing TCP badly.

A live video call uses UDP. A retransmitted frame arriving after its display time is useless, so the application prefers to conceal the loss and continue.

TCP's in-order delivery is actively harmful here, because one lost segment stalls delivery of everything behind it, producing a freeze rather than a glitch.

Bulk database replication uses TCP. Reliability is essential, the transfer is long enough for congestion control to reach a good rate, and ordering simplifies the receiving logic considerably.

The general rule: choose TCP when every byte matters and lateness is acceptable, and UDP when timeliness matters and some loss is acceptable.

Summary

The transport layer turns host-to-host best effort into process-to-process service with only header numbers and timers.

UDP demultiplexes on the destination port; TCP on all four address and port values, which is why one server port supports thousands of connections.

UDP has an 8-byte header, no handshake and no guarantees, which suits DNS, streaming, gaming and anything preferring loss to delay.

TCP sequence numbers count bytes and acknowledgements are cumulative. The three-way handshake exists because each direction's initial sequence number must be delivered and acknowledged, and because a delayed duplicate SYN would otherwise create a half-open connection. Release takes four steps and TIME_WAIT lasts twice the maximum segment lifetime.

Timeout is the estimated round-trip time plus four deviations, with weights 0.125 and 0.25. Karn's algorithm bars sampling from retransmitted segments and doubles the timeout instead. Fast retransmit acts on three duplicate acknowledgements.

Flow control protects the receiver and congestion control protects the network. Silly window syndrome is fixed by Clark's rule at the receiver and Nagle's algorithm at the sender, which interacts badly with delayed acknowledgements.

Slow start doubles the window per round trip, congestion avoidance adds one. A timeout halves the threshold and resets the window to one; three duplicate acknowledgements do the same under Tahoe but trigger fast recovery under Reno, which halves the window and stays in congestion avoidance.

Throughput is about MSS over RTT times one over the square root of the loss rate, so a hundredfold loss increase costs a tenfold throughput drop, and doubling the round-trip time halves throughput regardless of bandwidth.

At 10 Gbps the 32-bit sequence space wraps in about 3.4 seconds, far inside the maximum segment lifetime, which is why the timestamp option is mandatory on fast links.

The 16-bit window field is what forced window scaling, RST aborts a connection without the four-step release, and PSH forces immediate delivery to the application.

Choose TCP when every byte matters and lateness is tolerable, and UDP when timeliness matters and loss is tolerable, since TCP's in-order delivery turns a single loss into a stall of everything behind it.

Key formulas & results

Everything to memorise for the exam hall, in one card. Screenshot this for revision.

The organising principle
host-to-host best effort becomes process-to-process service using only header numbers and timers
Ports give process delivery, sequence numbers give order, acknowledgements plus timers give reliability, windows give flow and congestion control.
Demultiplexing keys
UDP uses the destination port alone; TCP uses source address, source port, destination address and destination port
The four-tuple is why one server port can hold thousands of distinct connections.
RTT estimation
EstimatedRTT = 0.875 times EstimatedRTT plus 0.125 times SampleRTT
Exponential averaging with alpha 0.125. The deviation is tracked separately against the previous estimate.
Deviation and timeout
DevRTT = 0.75 times DevRTT plus 0.25 times the absolute difference; Timeout = EstimatedRTT plus 4 times DevRTT
Including the deviation lets a stable link have a tight timeout and a variable one have slack, which a fixed multiplier cannot do.
Karn's algorithm
never sample RTT from a retransmitted segment; double the timeout on each retransmission instead
The acknowledgement could refer to either transmission, so the sample would be meaningless.
Slow start and congestion avoidance
slow start doubles the window per round trip; congestion avoidance adds one segment per round trip
The switch happens when the window reaches the slow start threshold. Together they form additive increase.
Loss response
timeout: threshold becomes half the window and the window becomes 1. Three duplicate ACKs under Reno: both become half the window
Tahoe treats both events identically. Reno's fast recovery recognises that arriving duplicates mean the pipe is not empty.
Fast retransmit trigger
resend after three duplicate acknowledgements without waiting for the timer
Three duplicates strongly suggest one segment was lost while later ones arrived.
Steady-state throughput
throughput is about MSS divided by RTT, times one over the square root of the loss rate
A hundredfold loss increase costs a tenfold throughput drop, and doubling RTT halves throughput regardless of available bandwidth.
Sequence wraparound
wrap time = 2 to the 32 bytes divided by the byte rate
About 3.4 seconds at 10 Gbps, far inside the maximum segment lifetime, which is why the timestamp option is mandatory on fast links.
TIME_WAIT duration
twice the maximum segment lifetime
Ensures the final acknowledgement arrives and that no old segment can reappear inside a new connection on the same port pair.
⚠️

Traps GATE sets — and how to dodge them

These are the exact option-traps and misreads that cost marks under negative marking.

WATCH OUT
Confusing flow control with congestion control
Flow control protects the receiver's buffer and uses the advertised window. Congestion control protects the network and uses the congestion window. The sender uses the minimum of the two.
Why it happens: Both are implemented with windows and both slow the sender down.
WATCH OUT
Treating TCP sequence numbers as segment counters
TCP sequence numbers count bytes. A segment carrying 1000 bytes advances the sequence number by 1000, not by 1.
Why it happens: Sliding window protocols at the data link layer number frames, so the habit carries over.
WATCH OUT
Halving the window on a timeout under Reno
A timeout always drops the window to one segment and restarts slow start, in both Tahoe and Reno. Only three duplicate acknowledgements trigger fast recovery.
Why it happens: Fast recovery halves the window, so halving becomes the remembered response to any loss.
WATCH OUT
Using the new estimate when computing the deviation
The deviation uses the absolute difference between the sample and the estimate before this update. Using the new one systematically underestimates variability.
Why it happens: The estimate is updated first in the written order, so it is the value at hand.
WATCH OUT
Sampling the round-trip time from a retransmitted segment
Karn's algorithm forbids it, because the acknowledgement may refer to the original transmission, making the sample far too large or too small.
Why it happens: An acknowledgement arrived, so it looks like a valid sample.
WATCH OUT
Claiming slow start is slow
Slow start doubles the window every round trip, which is exponential growth. It is slow only in its starting point of one segment, not in its rate.
Why it happens: The name says so.
WATCH OUT
Saying a two-way handshake would work if sequence numbers were random
The structural problem remains: the server would commit resources on a delayed duplicate SYN with no confirmation that a client is really there. The third message is what makes the server's commitment conditional.
Why it happens: Randomisation does address the guessing attack, which is the more memorable problem.
WATCH OUT
Choosing TCP for real-time media because it is reliable
In-order delivery means one lost segment stalls everything behind it, turning a recoverable glitch into a freeze. Real-time applications prefer UDP and conceal loss themselves.
Why it happens: Reliability sounds unconditionally better.

Exam-pattern practice

PYQ-style questions with full solutions. Work through them as a readiness check — mark yourself honestly and get your gap report at the end.

Readiness check

Are you exam-ready for Transport Layer: UDP, TCP, Flow & Congestion Control, Sockets?

10 problems from this chapter. Try each one, reveal the worked solution, mark yourself honestly — get your gap report at the end.

10 questions~7 min

5-minute revision

The whole chapter, distilled. Read this the night before the exam.

  • The layer has only header numbers and timers to work with
  • UDP demultiplexes on destination port; TCP on all four values
  • UDP header is 8 bytes, no handshake, no guarantees
  • TCP header is 20 to 60 bytes; sequence numbers count bytes; acknowledgements are cumulative
  • The 16-bit window field forced window scaling
  • RST aborts without the four-step release; PSH forces immediate delivery
  • Three-way handshake: each direction's initial sequence number must be delivered and acknowledged
  • Release takes four steps; TIME_WAIT is twice the maximum segment lifetime
  • EstimatedRTT uses alpha 0.125; DevRTT uses beta 0.25 against the previous estimate
  • Timeout is estimate plus four deviations
  • Karn's algorithm bars sampling retransmitted segments and doubles the timeout
  • Fast retransmit fires on three duplicate acknowledgements
  • Flow control protects the receiver; congestion control protects the network; the sender uses the minimum window
  • Clark's rule fixes silly window at the receiver; Nagle at the sender; Nagle plus delayed ACK causes stalls
  • Slow start doubles per round trip; congestion avoidance adds one
  • Timeout: threshold halves, window becomes 1. Three duplicates under Reno: both become half
  • Tahoe treats both losses identically; Reno adds fast recovery
  • Throughput is MSS over RTT times one over the square root of loss
  • Sequence space wraps in 3.4 seconds at 10 Gbps, hence the timestamp option
  • TCP when every byte matters; UDP when timeliness matters

GATE question blueprint

How this topic is asked, tier by tier — so you can prep to the pattern.

Typical weightage: 7

Question styleMarks eachTypical countWhat it tests
Congestion control31
TCP connection management11
Reliability and timers11
Flow control11
Sockets and UDP11

Exam-hall strategy

Battle-tested tips from mentors and toppers for this topic under the sectional clock.

  1. For congestion window traces, tabulate round trip number against window and threshold, and update the threshold explicitly at every loss event, since most errors come from forgetting it. Check whether the question specifies Tahoe or Reno before responding to duplicate acknowledgements. For timeout computation, apply the two recurrences in order and be careful that the deviation uses the pre-update estimate. Sequence number questions almost always want bytes rather than segments, so convert immediately. When asked why a mechanism exists, name the failure it prevents rather than describing what it does, since that is what the marks are for.

Beyond the exam

Where this skill shows up in the job you're competing for — and in life.

Every HTTP request rides on TCP's three-way handshake

Every HTTP request rides on TCP's three-way handshake, which is why HTTP/3 moved to QUIC over UDP to combine transport and cryptographic setup into fewer round trips

Window scaling and timestamps are enabled by default on e…

Window scaling and timestamps are enabled by default on every modern operating system precisely because of the 16-bit window and 32-bit sequence limits analysed here

The square-root throughput formula is why content deliver…

The square-root throughput formula is why content delivery networks exist: reducing round-trip time is the only lever that reliably increases single-connection throughput

Bufferbloat in home routers is a direct consequence of TC…

Bufferbloat in home routers is a direct consequence of TCP inferring congestion from loss, since oversized buffers delay the loss signal until latency has already collapsed

Load balancers must track the four-tuple to route packets…

Load balancers must track the four-tuple to route packets of one connection consistently, which is why connection state is what makes them hard to scale

Where else this topic is tested

Prepare once, score in every exam that asks it.

GATE CS
GATE DA
UGC NET Computer Science
ISRO Scientist SC
BARC Computer Science

Questions aspirants ask

Pulled from the Q&A community and mentor sessions.

Because the original design gave the network no way to signal. Explicit congestion notification was added later and marks packets instead of dropping them, but it requires support at both endpoints and in the routers between, so loss remains the universal signal. The cost is that a wireless link's corruption losses are misread as congestion.

Not usually. Linux defaults to CUBIC, which grows the window as a cubic function of time since the last loss, filling high bandwidth-delay paths far faster than Reno's linear increase. BBR goes further and abandons loss as a signal entirely, estimating bottleneck bandwidth and round-trip time directly.

Because they are independent constraints, not contributions. Exceeding the advertised window overruns the receiver's buffer; exceeding the congestion window overruns the network. Satisfying both means respecting the tighter one, and which one binds changes as conditions change.

The socket cannot be reused for a new connection with the same four-tuple, which is why a server restarted immediately after shutdown may fail to bind its port. The address reuse option relaxes this for the listening socket specifically, which is safe because the protection concerns established connections.

Because it delays small writes until an outstanding acknowledgement arrives, and delayed acknowledgements at the receiver may wait up to 200 milliseconds before sending one. The two mechanisms then wait for each other, producing exactly the latency that interactive applications cannot tolerate, so they set the no-delay option.

It provides two things that matter: process demultiplexing through ports and an optional checksum covering the payload. Everything else is deliberately absent so the application can supply exactly the semantics it wants, which is precisely how QUIC builds a full modern transport on top of it in user space.
Header Logo