IAE Academy

GATE CS

TCP

Flow control, congestion control and sockets

TCP gives a reliable, ordered byte stream between two sockets. It uses sequence numbers, a three-way handshake, a receiver window for flow control and a congestion window for congestion control. Problems on this topic ask you to trace handshakes and sequence numbers and to trace the congestion window round by round: slow start, congestion avoidance, and timeout versus three duplicate ACKs. They also ask you to compute throughput, utilisation, wrap-around time and the number of sequence-number bits needed.

12 previous-year questions · 12 solved · 6 practice questions

Ports, sockets and the UDP/TCP difference

A port is a 16-bit number (0 to 65535) that identifies a process on a host. A socket is one end of a communication, identified by an IP address and a port. A TCP connection is identified by four values: source IP, source port, destination IP and destination port. A UDP socket at the receiver is identified only by its destination IP and destination port, so datagrams from different senders to that address and port all reach the same socket. A TCP server, by contrast, has a separate connected socket for each client.

Property

UDP

TCP

Connection

Connectionless, no set-up

Connection-oriented (three-way handshake)

Reliability

None: no acknowledgement, no retransmission

Acknowledgements, retransmission, in-order delivery

Unit of data

Datagram, message boundaries kept

Byte stream, no message boundaries

Header size

8 bytes (fixed)

20 bytes minimum (up to 60 with options)

Flow and congestion control

None

Receiver window and congestion window

Typical use

Short queries, streaming, where speed matters more than perfection

File transfer, web pages, mail

TCP header field

Size

Note

Source port, destination port

16 bits each

Identify the two processes

Sequence number

32 bits

Number of the first data byte in the segment (or the ISN in a SYN)

Acknowledgement number

32 bits

Next byte expected; valid when the ACK flag is set

Header length (data offset)

4 bits

Counted in 4-byte words: 5 to 15, that is 20 to 60 bytes

Flags

1 bit each

URG, ACK, PSH, RST, SYN, FIN (newer headers also carry ECE and CWR)

Window

16 bits

Receiver window in bytes (scaled if the window-scale option is in use)

Checksum

16 bits

Covers header, data and a pseudo-header holding the IP addresses

Urgent pointer

16 bits

Used only when URG is set

EXAM TIP

TCP counts bytes, not segments. Every sequence number and acknowledgement number below refers to a byte position in the stream.

The socket API in order

The server prepares to receive with socket, bind, listen and accept. The client uses socket and connect. Once the connection is made, both sides use send and recv (or write and read) and finish with close.

SERVER                         CLIENT
s = socket()                   c = socket()
bind(s, local IP and port)
listen(s, backlog)
conn = accept(s)   <--------   connect(c, server IP and port)
                   (three-way handshake happens inside connect/accept)
recv(conn) / send(conn)  <-->  send(c) / recv(c)
close(conn)                    close(c)

Call

Who uses it

What it does

socket

Both

Creates a socket (TCP: stream type; UDP: datagram type)

bind

Server (client optional)

Attaches a local IP address and port to the socket

listen

Server, TCP only

Marks the socket as passive and sets the queue of pending connections

accept

Server, TCP only

Blocks until a connection is complete, then returns a NEW socket for that client; the listening socket stays open for more clients

connect

Client

Starts the three-way handshake with the server; the operating system picks a free local port if none is bound

send / recv

Both

Transfer data on a connected socket

close

Both

Starts connection release

EXAM TIP

A UDP server does not call listen or accept. It binds and then calls recvfrom and sendto for each datagram. The socket returned by accept is different from the listening socket.

Connection set-up and release, sequence numbers

  1. Segment 1 (client to server): SYN, seq = x, the client's initial sequence number.

  2. Segment 2 (server to client): SYN and ACK, seq = y, ack = x + 1.

  3. Segment 3 (client to server): ACK, seq = x + 1, ack = y + 1. This segment may already carry data.

A SYN and a FIN each use up exactly one sequence number, even though they carry no data. A pure ACK segment with no data uses none. The acknowledgement number is cumulative and names the next byte expected.

ACKNOWLEDGEMENT NUMBER

For a segment that arrives in order, with sequence number seq and L data bytes. Because the ACK is cumulative, an out-of-order segment brings back the previous ack number again (a duplicate ACK).

Release normally takes four segments, because each direction is closed separately: a FIN from the side that closes first, an ACK, a FIN from the other side, and an ACK. It takes three segments when the second side sends its FIN together with its ACK. The side that closed first sends the last ACK. It then waits in TIME_WAIT for twice the maximum segment lifetime before the connection is fully removed, so that a lost last ACK can be answered and old segments die out.

The maximum segment size (MSS) is the largest number of data bytes in one segment. Each side announces the MSS it can receive through an option in its SYN segment. With IPv4 and no IP or TCP options, it is usually the link MTU minus 40: a 20-byte IP header and a 20-byte TCP header.

Flow control, throughput and wrap-around

Flow control stops a fast sender from overflowing a slow receiver. In every ACK the receiver advertises its free buffer space as the receiver window (rwnd), in bytes. The sender keeps the amount of unacknowledged data at or below the window. The window field is 16 bits, so without the window-scale option the largest advertised window is bytes. With the window-scale option, agreed in the SYN segments, the window is bytes with . For example, filling a 1 Gbps path with a 100 ms RTT needs bytes, so , and .

If the receiver advertises a window of 0, the sender stops sending data. It sends small window probes on a persist timer until a non-zero window is advertised. Advertising or sending very small windows, a few bytes at a time, is called silly window syndrome. The receiver avoids it by not advertising a window until a reasonable amount of space is free, and the sender avoids it with Nagle's algorithm, which holds back small segments while earlier data is unacknowledged.

SENDER'S EFFECTIVE WINDOW

rwnd is the receiver's flow-control limit; cwnd is the congestion window from the next section.

MAXIMUM THROUGHPUT WITH WINDOW W

W is in bits when the rate is in bits per second. Assumes no loss, header overhead ignored and ACK transmission time negligible. When the window equals the bandwidth-delay product, the pipe is exactly full. If a question defines one cycle as RTT plus the transmission time of the window (or of a segment), use that cycle in place of RTT.

LINK UTILISATION (SLIDING WINDOW, CONTINUOUS)

Link rate times RTT is the bandwidth-delay product. Keep it in the same unit as W (bits or bytes).

SEQUENCE-NUMBER WRAP-AROUND TIME

The sequence field is 32 bits and counts bytes, so bytes pass before numbers repeat, if the sender sends continuously at the full rate.

MINIMUM SEQUENCE-NUMBER BITS

The condition is that sequence numbers (counting bytes) must not wrap around while a segment can still be alive in the network. The lifetime is the maximum segment lifetime given in the question. Convert the rate from bits to bytes per second by dividing by 8.

RETRANSMISSION TIMEOUT (STANDARD ESTIMATOR)

SRTT and RTTVAR , where R is a new RTT sample. RTTVAR is updated first, using the old SRTT. On the first sample, SRTT = R and RTTVAR = R/2, so RTO = 3R.

RTT samples are not taken from retransmitted segments, because the ACK cannot be matched to a particular transmission (Karn's algorithm). After each timeout the RTO is doubled (exponential back-off) until a fresh sample arrives. If a question gives its own smoothing weight α, use that weight. Check whether α multiplies the old estimate (new = α × old + (1 − α) × sample) or the sample. Unit convention: for data rates, 1 Mbps = bits per second and 1 Gbps = bits per second; 1 byte = 8 bits; a window or buffer quoted in KB is bytes only if the question says so, otherwise bytes.

Congestion control: slow start, avoidance and loss reactions

The congestion window (cwnd) limits the data in flight so that the network is not overloaded. The slow-start threshold (ssthresh) marks where growth changes from exponential to linear. In the traces below, window sizes are counted in units of MSS and cwnd starts at 1 MSS unless the question says otherwise. If a question gives windows in KB, divide by the MSS to work in segments.

  1. Slow start (cwnd below ssthresh): cwnd starts at 1 MSS and grows by 1 MSS for every ACK received. When every segment is acknowledged separately (no delayed ACKs), it therefore doubles every round trip.

  2. Congestion avoidance (cwnd at or above ssthresh): cwnd grows by about 1 MSS per round trip (additive increase), that is by MSS × MSS / cwnd per ACK.

  3. Timeout (both Tahoe and Reno): ssthresh becomes cwnd/2 (at least 2 MSS) and cwnd becomes 1 MSS; slow start restarts.

  4. Three duplicate ACKs means the original ACK followed by three more with the same acknowledgement number, four in all.

  5. Three duplicate ACKs, Tahoe: the missing segment is retransmitted at once (fast retransmit), then ssthresh = cwnd/2 and cwnd = 1 MSS, exactly as for a timeout.

  6. Three duplicate ACKs, Reno: fast retransmit, then ssthresh = cwnd/2 and cwnd = ssthresh (fast recovery). The sender continues in congestion avoidance with no return to slow start. This is the simplified model used in round-by-round traces. In the full algorithm cwnd is first set to ssthresh + 3 MSS, grows by 1 MSS for each further duplicate ACK, and drops back to ssthresh when a new ACK arrives.

MULTIPLICATIVE DECREASE

cwnd is the window at the moment the loss is detected. Unless the question says otherwise, take cwnd/2 in whole MSS (rounded down for an odd window).

Event

ssthresh after

cwnd after

Next phase

Timeout (Tahoe or Reno)

cwnd/2

1 MSS

Slow start

3 duplicate ACKs, Tahoe

cwnd/2

1 MSS

Slow start

3 duplicate ACKs, Reno (simplified)

cwnd/2

ssthresh

Congestion avoidance

Conventions used when tracing round by round. Round is the round trip in which the sender transmits cwnd segments. In slow start the window doubles from one round to the next but is capped at ssthresh: if doubling would pass ssthresh, the next round uses exactly ssthresh, and from then on the window grows by 1 per round. After a loss in round , round uses the new cwnd. If the question states a different convention, follow it.

EXAM TIP

Do not halve cwnd twice, and do not halve the old ssthresh. The new ssthresh is half of the cwnd at the time of the loss. A timeout is treated as more serious than three duplicate ACKs, because duplicate ACKs show that later segments are still getting through.

Worked examples

WORKED EXAMPLE

A TCP sender starts with cwnd = 1 MSS and ssthresh = 16 MSS. A timeout occurs in the round in which cwnd has reached 20 MSS. Trace round by round with the conventions above (doubling capped at ssthresh, then +1 per round), counting the first round as round 1. Find cwnd in round 15.

Solution
  1. Slow start: rounds 1 to 5 have cwnd 1, 2, 4, 8, 16. Now cwnd = ssthresh = 16, so congestion avoidance starts.

  2. Rounds 6, 7, 8, 9 have cwnd 17, 18, 19, 20. The timeout happens in round 9 (cwnd = 20).

  3. New ssthresh = 20/2 = 10 MSS; cwnd = 1 MSS.

  4. Round 10: 1. Round 11: 2. Round 12: 4. Round 13: 8.

  5. Round 14: doubling would give 16, which passes ssthresh, so cwnd = 10. Round 15: congestion avoidance adds 1, so cwnd = 11.

Answer: cwnd in round 15 = 11 MSS.

WORKED EXAMPLE

A TCP connection uses a window of 125000 bytes on a 100 Mbps link (1 Mbps = bits per second) with RTT = 40 ms. There is no loss; ignore header overhead. Find the maximum throughput and the link utilisation. Then find the wrap-around time of the sequence numbers at the throughput reached.

Solution
  1. Window in bits = 125000 × 8 = bits.

  2. Bandwidth-delay product = bits. This is larger than the window, so the window is the limit.

  3. Throughput = bits per second = 25 Mbps.

  4. Utilisation = 25/100 = 0.25 = 25%.

  5. Wrap-around at 25 Mbps = seconds.

Answer: Throughput 25 Mbps, utilisation 25%, wrap-around about 1374 seconds.

PREVIOUS-YEAR QUESTIONS

12 questions from the CS papers

Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.

See these papers in full: GATE CSE 2026 Set 1 · GATE CSE 2026 Set 2 · GATE CSE 2025 Set 1 · GATE CSE 2025 Set 2 · GATE CSE 2024 Set 1 · GATE CSE 2024 Set 2 · GATE CSE 2023 · GATE CSE 2022 · GATE CSE 2020 · GATE CSE 2018

GATE 2026 CS1 Q.18

GATE 2026 · CS1Q.18 · 1 mark · MCQ

With respect to a TCP connection between a client and a server, which one of the following statements is true?

  1. (A)

    The client and server use a two-way handshake mechanism before the start of data transmission

  2. (B)

    The server cannot initiate closing of the connection before the client initiates closing of the connection

  3. (C)

    The TCP connection is half-duplex

  4. (D)

    The client and server can initiate closing of the connection at the same time

Answer and solution
See the question in the paper
GATE 2026 CS1 Q.18: answer and solution

GATE 2026 CS1 Q.44

GATE 2026 · CS1Q.44 · 2 marks · MCQ

A TCP sender successfully establishes a connection with a TCP receiver and starts the transmission of segments. The TCP congestion control mechanism's slow-start threshold is set to 10000 segments. Assume that the round-trip time is fixed at 1 millisecond. Assume that the sender always has data to send, the segments are numbered from 1, and no segment is lost. Let t denote the time (in milliseconds) at which the transmission of segment number 2000 starts.

Which one of the following options is correct?

  1. (A)

    9 \le t < 10

  2. (B)

    10 \le t < 11

  3. (C)

    11 \le t < 12

  4. (D)

    12 \le t < 13

Answer and solution
See the question in the paper
GATE 2026 CS1 Q.44: answer and solution

GATE 2026 CS2 Q.58

GATE 2026 · CS2Q.58 · 2 marks · NAT

Consider a new TCP connection between a sender and a receiver. The receiver advertised window is constant at 48 KB, the maximum segment size (MSS) is 2 KB, and the slow start threshold for TCP congestion control is 16 KB. Assume that there are no timeouts or duplicate acknowledgements. The number of rounds of transmission required for the congestion control algorithm of the TCP connection to reach the congestion avoidance phase is ________. (answer in integer)

Note: 1K=2^10

Answer and solution
See the question in the paper
GATE 2026 CS2 Q.58: answer and solution

GATE 2025 CS1 Q.22

GATE 2025 · CS1Q.22 · 1 mark · MSQ

Consider the 3-way handshaking protocol for TCP connection establishment. Let the three packets exchanged during the connection establishment be denoted as P1, P2, and P3, in order. Which of the following option(s) is/are TRUE with respect to TCP header flags that are set in the packets?

  1. (A)

    P3: SYN = 1, ACK = 1

  2. (B)

    P2: SYN = 1, ACK = 1

  3. (C)

    P2: SYN = 0, ACK = 1

  4. (D)

    P1: SYN = 1

Answer and solution
See the question in the paper
GATE 2025 CS1 Q.22: answer and solution

GATE 2025 CS2 Q.16

GATE 2025 · CS2Q.16 · 1 mark · MCQ

Consider the following statements:
(i) Address Resolution Protocol (ARP) provides a mapping from an IP address to the corresponding hardware (link-layer) address.
(ii) A single TCP segment from a sender S to a receiver R cannot carry both data from S to R and acknowledgement for a segment from R to S.

Which ONE of the following is CORRECT?

  1. (A)

    Both (i) and (ii) are TRUE

  2. (B)

    (i) is TRUE and (ii) is FALSE

  3. (C)

    (i) is FALSE and (ii) is TRUE

  4. (D)

    Both (i) and (ii) are FALSE

Answer and solution
See the question in the paper
GATE 2025 CS2 Q.16: answer and solution

GATE 2024 CS1 Q.29

GATE 2024 · CS1Q.29 · 1 mark · MSQ

TCP client P successfully establishes a connection to TCP server Q. Let denote the sequence number in the SYN sent from P to Q. Let denote the acknowledgement number in the SYN ACK from Q to P. Which of the following statements is/are CORRECT?

  1. (A)

    The sequence number is chosen randomly by P

  2. (B)

    The sequence number is always 0 for a new connection

  3. (C)

    The acknowledgement number is equal to

  4. (D)

    The acknowledgement number is equal to

Answer and solution
See the question in the paper
GATE 2024 CS1 Q.29: answer and solution

GATE 2024 CS2 Q.54

GATE 2024 · CS2Q.54 · 2 marks · NAT

Consider a TCP connection operating at a point of time with the congestion window of size 12 MSS (Maximum Segment Size), when a timeout occurs due to packet loss. Assuming that all the segments transmitted in the next two RTTs (Round Trip Time) are acknowledged correctly, the congestion window size (in MSS) during the third RTT will be ______

Answer and solution
See the question in the paper
GATE 2024 CS2 Q.54: answer and solution

GATE 2023 CS Q.50

GATE 2023 · CSQ.50 · 2 marks · MSQ

Suppose you are asked to design a new reliable byte-stream transport protocol like TCP. This protocol, named myTCP, runs over a 100 Mbps network with Round Trip Time of 150 milliseconds and the maximum segment lifetime of 2 minutes.

Which of the following is/are valid lengths of the Sequence Number field in the myTCP header?

  1. (A)

    30 bits

  2. (B)

    32 bits

  3. (C)

    34 bits

  4. (D)

    36 bits

Answer and solution
See the question in the paper
GATE 2023 CS Q.50: answer and solution

GATE 2022 CS Q.60

GATE 2022 · CSQ.60 · 2 marks · NAT

Consider the data transfer using TCP over a 1 Gbps link. Assuming that the maximum segment lifetime (MSL) is set to 60 seconds, the minimum number of bits required for the sequence number field of the TCP header, to prevent the sequence number space from wrapping around during the MSL is ______.

Answer and solution
See the question in the paper
GATE 2022 CS Q.60: answer and solution

GATE 2020 CS Q.55

GATE 2020 · CSQ.55 · 2 marks · NAT

Consider a TCP connection between a client and a server with the following specifications: the round trip time is 6 ms, the size of the receiver advertised window is 50 KB, slow-start threshold at the client is 32 KB, and the maximum segment size is 2 KB. The connection is established at time t = 0. Assume that there are no timeouts and errors during transmission. Then the size of the congestion window (in KB) at time t + 60 ms after all acknowledgements are processed is ______.

Answer and solution
See the question in the paper
GATE 2020 CS Q.55: answer and solution

GATE 2018 CS Q.14

GATE 2018 · CSQ.14 · 1 mark · MCQ

Consider the following statements regarding the slow start phase of the TCP congestion control algorithm. Note that cwnd stands for the TCP congestion window and MSS denotes the Maximum Segment Size.

(i) The cwnd increases by 2 MSS on every successful acknowledgment.
(ii) The cwnd approximately doubles on every successful acknowledgement.
(iii) The cwnd increases by 1 MSS every round trip time.
(iv) The cwnd approximately doubles every round trip time.

Which one of the following is correct?

  1. (A)

    Only (ii) and (iii) are true

  2. (B)

    Only (i) and (iii) are true

  3. (C)

    Only (iv) is true

  4. (D)

    Only (i) and (iv) are true

Answer and solution
See the question in the paper
GATE 2018 CS Q.14: answer and solution

OTHER EXAMS

ISRO: 1 question

From ISRO's Scientist/Engineer written test: ISRO CS 2025. They are not counted in the GATE numbers on this page.

PRACTICE

6 questions to test yourself

PRACTICE 11 mark · MCQ

A TCP client opens a connection with initial sequence number 2000, and the server's initial sequence number is 7000. The third segment of the handshake is a pure ACK carrying no data. What are its sequence number and acknowledgement number?

  1. (A)

    seq = 2000, ack = 7000

  2. (B)

    seq = 2001, ack = 7001

  3. (C)

    seq = 2001, ack = 7000

  4. (D)

    seq = 2000, ack = 7001

Answer and solution

Answer: (B)

  1. The SYN used up one sequence number, so the client's next byte number is 2000 + 1 = 2001.

  2. The server's SYN also used up one number, so the client acknowledges 7000 + 1 = 7001.

  3. So seq = 2001 and ack = 7001.

PRACTICE 22 marks · NAT

A TCP sender starts with cwnd = 1 MSS and ssthresh = 8 MSS. The window grows by slow start (doubling each round, capped at ssthresh) and then by 1 MSS per round. In the round in which cwnd = 12 MSS, three duplicate ACKs arrive. The sender uses TCP Reno: the new ssthresh is cwnd/2, cwnd is set to the new ssthresh, and then cwnd grows by 1 MSS per round. A loss in round n means round n+1 uses the new window. Counting the first round as round 1, what is cwnd, in MSS, in round 11?

Answer and solution

Answer:

  1. Rounds 1 to 4: cwnd = 1, 2, 4, 8 (reaches ssthresh).

  2. Rounds 5 to 8: 9, 10, 11, 12. Loss in round 8.

  3. Reno: ssthresh = 12/2 = 6 and cwnd = 6, so round 9 has cwnd 6.

  4. Round 10: 7. Round 11: 8.

PRACTICE 32 marks · NAT

A TCP connection has a window of 50000 bytes, the round-trip time is 80 ms and the link rate is 10 Mbps (1 Mbps = bits per second, 1 byte = 8 bits). There is no loss. Ignore header overhead and the transmission time of ACKs. What is the maximum throughput in Mbps?

Answer and solution

Answer: (accepted range )

  1. Bandwidth-delay product = bits = 100000 bytes.

  2. The window of 50000 bytes is smaller than this, so the window limits the rate.

  3. Throughput = 50000 × 8 / 0.08 = bits per second = 5 Mbps.

PRACTICE 42 marks · NAT

TCP sequence numbers are 32 bits and count bytes. A sender transmits continuously at a line rate of 400 Mbps (1 Mbps = bits per second, 1 byte = 8 bits). After how many seconds do the sequence numbers wrap around? Give the answer to one decimal place.

Answer and solution

Answer: (accepted range )

  1. Number of bytes before wrap-around = .

  2. In bits: .

  3. Time = seconds.

PRACTICE 51 mark · NAT

A protocol numbers every byte, like TCP. It runs on a link of 1 Gbps (1 Gbps = bits per second, 1 byte = 8 bits), and a segment can stay alive in the network for at most 60 seconds. What is the minimum number of bits in the sequence-number field so that sequence numbers do not wrap around within the segment lifetime?

Answer and solution

Answer:

  1. Bytes sent in 60 seconds = .

  2. , which is less than .

  3. , which is at least .

  4. So the minimum is 33 bits.

PRACTICE 61 mark · MSQ

Which of the following statements about TCP are correct?

  1. (A)

    A SYN segment uses up one sequence number even though it carries no data.

  2. (B)

    A pure ACK segment with no data uses up one sequence number.

  3. (C)

    On three duplicate ACKs, Reno does not reduce cwnd to 1 MSS.

  4. (D)

    The sender's usable window is the smaller of the receiver window and the congestion window.

Answer and solution

Answer: (A), (C), (D)

  1. A is true: SYN and FIN each use one sequence number.

  2. B is false: an ACK with no data and no SYN or FIN uses no sequence number.

  3. C is true: Reno sets cwnd to the new ssthresh (about half), unlike Tahoe and unlike a timeout.

  4. D is true: usable window = min(rwnd, cwnd).

OFFICIAL GATE 2027 SYLLABUS WORDING

Copied from the GATE 2027 syllabus; see all 2027 syllabi.

GATE CS

TCP- flow control and congestion control, socket API

Preparing in Kolkata? IAE Academy's course for GATE CSE.