Autocoder

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.

NumericalsSequence and ACK numbers, cwnd growth, IP fragmentation, RTT estimation
Header sizesTCP 20 to 60 bytes, IPv4 20 to 60 bytes
Questions16

Header fields worth knowing by heart

TCP/IP Interview Questions: questions with worked answers

  1. 1

    What are the layers of the TCP/IP model and an example protocol at each?

    easy

    Application (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. 2

    Explain the TCP three-way handshake.

    easy

    The 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.

    text
    Client                    Server
      | --- SYN, seq=x ---------> |
      | <-- SYN+ACK, seq=y, ack=x+1 |
      | --- ACK, seq=x+1, ack=y+1 -> |
      |        ESTABLISHED         |
  3. 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.

    medium

    The 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. 4

    How does TCP close a connection and what is TIME_WAIT?

    medium

    Each 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. 5

    How does TCP provide reliability?

    medium

    With 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. 6

    Differentiate flow control and congestion control.

    medium

    Flow 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. 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.

    medium

    Slow 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. 8

    What is AIMD and why does TCP use it?

    medium

    Additive 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. 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.

    medium

    Each 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. 10

    Numerical: EstimatedRTT is 100 ms. A new sample RTT is 140 ms, and alpha = 0.125. Update EstimatedRTT, and explain the retransmission timeout.

    medium

    EstimatedRTT = (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. 11

    What is the role of the TCP window size field and window scaling?

    medium

    The 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. 12

    What is a SYN flood and how is it mitigated?

    medium

    The 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. 13

    What is ICMP and where is it used?

    medium

    The 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. 14

    What is the Nagle algorithm and when would you disable it?

    hard

    Nagle'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. 15

    How does TCP detect and recover from packet loss using fast retransmit?

    hard

    When 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. 16

    Why does TCP use a random initial sequence number?

    hard

    A 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

More in CS Fundamentals Interview Questions

See all in this section