TCP/IP Interview Questions: Handshake, Congestion Control and Numericals
Last updated 2026-11-19
TCP/IP questions go deeper than the layer names. Interviewers ask you to walk through the three-way handshake with real sequence numbers, explain why TIME_WAIT exists, describe how slow start grows the congestion window, or fragment an IP datagram to fit an MTU. This page works those problems step by step and covers the header fields that most questions hinge on.
It builds on the layered model in OSI model interview questions and pairs with TCP vs UDP interview questions and HTTP and HTTPS interview questions. For the round-level plan see how to crack a computer networks interview.
| Numericals | Sequence and ACK numbers, cwnd growth, IP fragmentation, RTT estimation |
|---|---|
| Header sizes | TCP 20 to 60 bytes, IPv4 20 to 60 bytes |
| Questions | 16 |
Header fields worth knowing by heart
- TCP: source and destination port (16 bits each), sequence number (32), acknowledgement number (32), header length, flags (SYN, ACK, FIN, RST, PSH, URG), window size (16), checksum.
- IPv4: version, header length (IHL, in 32-bit words), total length (16 bits, so max 65535), identification, flags (DF, MF), fragment offset (in 8-byte units), TTL, protocol, header checksum, source and destination address.
- A SYN or FIN flag consumes one sequence number; a pure ACK consumes none.
TCP/IP Interview Questions: questions with worked answers
1 What are the layers of the TCP/IP model and an example protocol at each?
easyApplication (HTTP, DNS, SMTP, SSH), Transport (TCP, UDP), Internet (IP, ICMP, routing protocols) and Network access or link (Ethernet, Wi-Fi, ARP). When five layers are used, link and physical are listed separately. Data passes down the stack at the sender, gaining a header at each layer, and up at the receiver.
2 Explain the TCP three-way handshake.
easyThe client sends SYN with its initial sequence number x. The server replies SYN-ACK with its own initial sequence number y and acknowledgement x + 1. The client sends ACK with acknowledgement y + 1, and the connection is established. The handshake agrees on initial sequence numbers and confirms that both sides can send and receive. Three messages are the minimum for both directions to confirm each other's sequence number.
textClient Server | --- SYN, seq=x ---------> | | <-- SYN+ACK, seq=y, ack=x+1 | | --- ACK, seq=x+1, ack=y+1 -> | | ESTABLISHED |3 Numerical: A client with initial sequence number 1000 sends 3000 bytes in 1000-byte segments after the handshake. Give the sequence numbers and the ACKs.
mediumThe SYN consumed sequence number 1000, so the first data byte is 1001. Segment 1 carries bytes 1001 to 2000 (seq = 1001), segment 2 has seq = 2001, segment 3 has seq = 3001. The server's cumulative ACK numbers are the next byte expected: 2001, 3001 and 4001. If segment 2 were lost, the server would keep sending ACK 2001 for segment 3 (a duplicate ACK), and the sender would retransmit.
4 How does TCP close a connection and what is TIME_WAIT?
mediumEach direction is closed separately: the side that finishes sends FIN, the peer ACKs it, later the peer sends its own FIN and gets an ACK, so four messages, though the middle two are often combined. The side that sent the last ACK enters TIME_WAIT for 2 x MSL (commonly 60 seconds on Linux) so that a lost final ACK can be re-sent and old duplicate segments from this connection expire before the same port pair is reused. Many connections in TIME_WAIT on a busy server are normal, but ephemeral port exhaustion may happen.
5 How does TCP provide reliability?
mediumWith sequence numbers to order data and detect duplicates, cumulative acknowledgements, retransmission on timeout or after three duplicate ACKs (fast retransmit), a checksum to detect corruption, flow control using the receiver's advertised window, and congestion control. The retransmission timeout is adapted from measured round-trip times.
6 Differentiate flow control and congestion control.
mediumFlow control protects the receiver: it advertises a receive window (rwnd) in each ACK so that the sender never has more unacknowledged data than the receiver's buffer can hold. Congestion control protects the network: the sender maintains a congestion window (cwnd) and the amount in flight is limited to min(cwnd, rwnd). Flow control is an end-to-end agreement; congestion control reacts to signals such as loss or delay from the shared path.
7 Numerical: Using TCP Tahoe with initial cwnd = 1 MSS and ssthresh = 16 MSS, give cwnd for each RTT until a timeout occurs at cwnd = 20, and the values after.
mediumSlow start doubles cwnd each RTT until it reaches ssthresh: 1, 2, 4, 8, 16. At 16 congestion avoidance begins and cwnd grows by 1 MSS per RTT: 17, 18, 19, 20. A timeout at cwnd = 20 sets ssthresh = 20 / 2 = 10 and cwnd = 1. Slow start then gives 1, 2, 4, 8, 16 but is capped at ssthresh = 10, so the sequence is 1, 2, 4, 8, 10, 11, 12 and so on. Reno on three duplicate ACKs would instead set cwnd = ssthresh = 10 directly (fast recovery).
8 What is AIMD and why does TCP use it?
mediumAdditive increase, multiplicative decrease: during congestion avoidance cwnd grows by about 1 MSS per RTT, and on loss it is halved. This combination has been shown to converge to a fair and efficient share of a bottleneck among competing flows, whereas additive-increase with additive-decrease or multiplicative-increase would not. The result is the sawtooth pattern of throughput.
9 Numerical: A 4000-byte IPv4 datagram (20-byte header, 3980 bytes of data) is sent over a link with MTU 1500. Show the fragments.
mediumEach fragment's data must be a multiple of 8 bytes, and the maximum data per fragment is 1500 - 20 = 1480 (1480 / 8 = 185, so it is already a multiple). Fragment 1: 1480 bytes of data, offset 0, MF = 1, total length 1500. Fragment 2: 1480 bytes, offset 1480 / 8 = 185, MF = 1, total length 1500. Fragment 3: 3980 - 2960 = 1020 bytes, offset 370, MF = 0, total length 1040. All fragments share the identification field, and only the destination reassembles them.
10 Numerical: EstimatedRTT is 100 ms. A new sample RTT is 140 ms, and alpha = 0.125. Update EstimatedRTT, and explain the retransmission timeout.
mediumEstimatedRTT = (1 - 0.125) x 100 + 0.125 x 140 = 87.5 + 17.5 = 105 ms, an exponentially weighted moving average. The deviation DevRTT is smoothed the same way from |sample - estimate|, and RTO = EstimatedRTT + 4 x DevRTT, so jittery paths get a longer timeout. On a retransmission timeout the RTO is doubled (exponential backoff). Karn's algorithm excludes retransmitted segments from RTT samples since the ACK is ambiguous.
11 What is the role of the TCP window size field and window scaling?
mediumThe 16-bit window field limits the receive window to 65,535 bytes, which restricts throughput on high bandwidth-delay paths: at 100 ms RTT it gives at most 65535 x 8 / 0.1 = 5.2 Mbps. The window scale option, agreed in the SYN, multiplies the field by 2^n (up to 2^14) allowing windows up to about 1 GB.
12 What is a SYN flood and how is it mitigated?
mediumThe attacker sends many SYN packets (often with forged source addresses) so that the server allocates state for half-open connections and its backlog fills, refusing real clients. SYN cookies defend against it: the server encodes the connection state in the sequence number of the SYN-ACK and keeps no state until a valid ACK returns. Other mitigations are shortening the SYN timeout, increasing the backlog and rate limiting. See network security interview questions.
13 What is ICMP and where is it used?
mediumThe Internet Control Message Protocol carries error and diagnostic messages for IP: destination unreachable, time exceeded (used by traceroute), redirect and echo request and reply (ping). It runs directly over IP (protocol number 1), not over TCP or UDP. Path MTU discovery depends on the ICMP fragmentation-needed message, so blocking all ICMP can cause mysterious stalls on large transfers.
14 What is the Nagle algorithm and when would you disable it?
hardNagle's algorithm reduces tiny packets: if there is unacknowledged data in flight, the sender buffers small writes until an ACK arrives or a full segment accumulates. This saves bandwidth but combined with delayed ACKs on the receiver it can add up to about 40 ms of latency for request-response traffic with small writes. Latency-sensitive applications set the TCP_NODELAY socket option to disable it.
15 How does TCP detect and recover from packet loss using fast retransmit?
hardWhen one segment is lost but later ones arrive, the receiver sends a duplicate ACK for the last in-order byte each time. After three duplicate ACKs, the sender retransmits the missing segment immediately without waiting for the timeout. With SACK the receiver reports which blocks it holds so the sender retransmits only the gaps. Fast recovery then halves cwnd instead of collapsing it to 1, keeping throughput up.
16 Why does TCP use a random initial sequence number?
hardA predictable initial sequence number lets an attacker forge segments in an existing connection or spoof a connection, and a fixed one would let old segments from a previous connection with the same port pair be mistaken for new data. Operating systems generate the number from a secret keyed hash of the connection 4-tuple plus a clock, which keeps it unpredictable yet increasing over time.
Frequently asked questions
Why is a three-way handshake needed instead of two?
Both sides must choose and confirm an initial sequence number. Two messages would let the server think a connection is open when the client's SYN was an old duplicate, and the client could not confirm that the server received its number.
What is the difference between a segment, a packet and a frame?
A segment is the transport-layer unit, a packet is the network-layer unit and a frame is the link-layer unit. Each wraps the one above with its own header.
What is the maximum size of an IP packet?
65,535 bytes, because the total length field has 16 bits. In practice packets are limited by the link MTU, 1500 bytes on Ethernet, unless jumbo frames are used.
What is MSS?
The maximum segment size is the largest amount of data TCP will send in one segment, announced in the SYN. It is usually the MTU minus 40 bytes of TCP and IP headers, so 1460 for Ethernet.
Related guides
- TCP vs UDP Interview Questions with Socket Code and Numericals
- OSI Model Interview Questions: Layers, PDUs, Devices and Encapsulation
- Computer Networks Interview Questions with Worked Answers and Numericals
- HTTP and HTTPS Interview Questions: Methods, Status Codes, TLS and Caching
- Network Security Interview Questions: Cryptography, Firewalls and Attacks
- IP Addressing and Subnetting Interview Questions with Worked Solutions
More in CS Fundamentals Interview Questions
- Transactions and ACID Interview Questions
- What Happens When You Type a URL in the Browser: The Complete Answer
- Abstraction and Encapsulation Interview Questions
- Cache Memory and Computer Organization Interview Questions with Numericals
- Caching Interview Questions and Answers
- Cloud Computing Basics Interview Questions with Answers
- Computer Architecture Interview Questions with Numericals
- Computer Networks Interview Questions with Worked Answers and Numericals
- CPU Scheduling Interview Questions with Gantt Chart Numericals
- Database Indexing Interview Questions
- DBMS Concurrency Control Interview Questions
- DBMS Interview Questions and Answers