TCP/IP interview questions and answers
TCP/IP interview questions go past the textbook handshake: interviewers ask what each header field is for, how a connection moves through its states, why throughput stalls on a long link, and how you would find a problem with packet captures. Fundamentals cover IP, ports, ICMP and the MTU. Senior and scenario questions test whether you can explain a stuck CLOSE_WAIT, a black-holed large packet or a reset from a load balancer with evidence instead of guesses.
By Evin JohnPublished 8 min read
Who gets TCP/IP questions, and how deep
Backend and infrastructure engineers meet TCP/IP when a service times out, a connection pool misbehaves or a transfer runs slower than the link allows. That is why SRE, platform, networking software, embedded and security interviews go deeper than general software rounds. Expect a mix of whiteboard questions, a "read this capture" exercise and an incident story where you narrate how you narrowed the cause.
- Protocol basicsShort questions on layers, headers and what each protocol is responsible for. A strong candidate answers in one or two sentences and adds the field name.
- Mechanism deep diveOne area explored in depth: connection states, retransmission, flow control or fragmentation. The interviewer keeps asking "and then what happens?"
- Troubleshooting scenarioA symptom such as intermittent timeouts or slow uploads. You describe what you would capture, which counters you would read and what each result would rule out.
- Socket code (some roles)Systems roles may ask you to sketch a client or server with the sockets API and explain framing, partial reads and error handling.
Fundamentals: IP, ports and ICMP
| Question | What it tests | What a strong answer shows |
|---|---|---|
| How do the four layers of the TCP/IP model map to OSI? | Model | Link covers OSI 1 and 2, Internet is layer 3, Transport is layer 4, and Application folds OSI 5 to 7 together. Say that real protocols do not split as cleanly as either diagram. |
| What does IP promise about delivery? | Best effort | Nothing beyond a best attempt: packets can be lost, duplicated, delayed or reordered. Reliability, ordering and pacing are TCP's job, or the application's on UDP. |
| What is the TTL field for? | Header fields | Each router decrements it and drops the packet at zero, sending an ICMP Time Exceeded message back. It stops routing loops from circulating packets forever. |
| How does traceroute work? | ICMP in use | It sends probes with TTL 1, 2, 3 and so on, and each router that drops one reports back, revealing the path hop by hop. Missing hops often just mean a router does not answer, not that traffic is lost there. |
| What identifies a TCP connection? | Five-tuple | Protocol, source IP, source port, destination IP and destination port. Two connections to the same server port differ by the client's address or ephemeral port. |
| What is an ephemeral port? | Client side | A short-lived source port the OS picks for an outgoing connection from a configured range. Many short connections to one destination can use the range up. |
| MTU versus MSS? | Sizes | MTU is the largest IP packet a link carries, commonly 1,500 bytes on Ethernet. MSS is the largest TCP payload per segment, so on plain IPv4 it is the MTU minus 40 bytes of IP and TCP headers: 1,460. |
| What does the protocol field in the IP header say? | Demultiplexing | Which transport the payload belongs to: 6 for TCP, 17 for UDP, 1 for ICMP. IPv6 calls it Next Header and can chain extension headers. |
| Name three main differences between IPv4 and IPv6 headers. | IPv6 | IPv6 has 128-bit addresses, a fixed 40-byte base header with no header checksum, and routers never fragment; only the sender can. Neighbor Discovery replaces ARP. |
| What does the TCP checksum cover? | Integrity | The TCP header, the payload and a pseudo-header with the source and destination addresses, so a segment delivered to the wrong host fails the check. It is weak against deliberate tampering, which is why TLS adds its own integrity. |
| When would you use UDP for a new protocol? | Design | When you need low latency, multicast or your own reliability rules, such as DNS queries, media or QUIC. You then own retransmission, ordering and congestion behavior. |
A popular warm-up is to hand you raw bytes and ask what they are. Being able to pull fields out of a header shows you know where each one lives.
import ipaddress
import struct
# One captured SYN: a 20-byte IPv4 header, then a 24-byte TCP header with an MSS option
pkt = bytes.fromhex(
"4500002c1c46400040063241c000020ac6336407"
"c93a01bb000003e8000000006002faf0e2120000020405b4"
)
ver_ihl, _, total_len, ident, frag, ttl, proto, _, src, dst = struct.unpack("!BBHHHBBH4s4s", pkt[:20])
ihl = (ver_ihl & 0x0F) * 4 # header length in bytes
dont_fragment = bool(frag & 0x4000)
print(ver_ihl >> 4, ihl, total_len, ttl, proto, dont_fragment) # 4 20 44 64 6 True
print(ipaddress.ip_address(src), "->", ipaddress.ip_address(dst)) # 192.0.2.10 -> 198.51.100.7
sport, dport, seq, ack, off, flags, window = struct.unpack("!HHIIBBH", pkt[ihl:ihl + 16])
tcp_len = (off >> 4) * 4
names = [n for bit, n in [(0x02, "SYN"), (0x10, "ACK"), (0x01, "FIN"), (0x04, "RST")] if flags & bit]
print(sport, dport, seq, tcp_len, names, window) # 51514 443 1000 24 ['SYN'] 64240
kind, length, mss = struct.unpack("!BBH", pkt[ihl + 20:ihl + 24])
print(kind, mss) # 2 1460: option 2 is MSS
def checksum(data: bytes) -> int:
"""Internet checksum: one's complement of the one's complement sum of 16-bit words."""
if len(data) % 2:
data += b"\x00"
total = sum(struct.unpack(f"!{len(data) // 2}H", data))
while total >> 16:
total = (total & 0xFFFF) + (total >> 16)
return ~total & 0xFFFF
print(checksum(pkt[:ihl])) # 0: a valid header, checksum field included, sums to zeroIntermediate: connection states and reliability
| Question | What it tests | What a strong answer shows |
|---|---|---|
| Draw the TCP states for a normal open and close. | State machine | Client: CLOSED, SYN_SENT, ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, TIME_WAIT. Server: LISTEN, SYN_RECEIVED, ESTABLISHED, CLOSE_WAIT, LAST_ACK, CLOSED. Whoever closes first ends in TIME_WAIT. |
| Thousands of sockets sit in CLOSE_WAIT. What does that tell you? | Diagnosis | The peer has closed, and your own process received the FIN but never called close. It is almost always an application bug such as a leaked connection or a missing close on an error path, not a kernel setting. |
| What are the SYN queue and the accept queue? | Backlog | Half-open connections wait in the SYN queue until the handshake finishes, then move to the accept queue until the application calls accept. The listen backlog bounds the second one; when it overflows, new handshakes are dropped or reset. |
| What are SYN cookies? | Defense | Under a SYN flood the server encodes the connection details into its initial sequence number instead of storing state, and rebuilds the entry when a valid ACK returns. Some TCP options can be lost while they are in use. |
| How does TCP decide when to retransmit? | Timers | It keeps a smoothed RTT and its variance to set the retransmission timeout, and backs off exponentially on repeated loss. Three duplicate ACKs trigger fast retransmit without waiting for the timer. |
| What does selective acknowledgment add? | SACK | The receiver reports which later blocks arrived, so the sender resends only the holes instead of everything after the first loss. Both sides must agree to it in the handshake. |
| Why does window scaling exist? | Window size | The window field is 16 bits, so the most a receiver can advertise is 65,535 bytes. The scale option, agreed during the handshake, shifts that value left to allow much larger windows on fast, long links. |
| What does TCP keepalive do, and why is it often not enough? | Idle connections | After a long idle period the kernel sends probes and closes the connection if none are answered. Default timers are often hours, while firewalls and load balancers drop idle state much sooner, so apps send their own heartbeats or lower the interval. |
| FIN versus RST? | Closing | FIN is an orderly close of one direction, and data already sent still arrives. RST aborts at once and discards unsent data. A RST also comes back when you connect to a port nothing listens on. |
| What does SO_REUSEADDR change? | Sockets API | It lets a restarted server bind its listening port while old connections from the previous process sit in TIME_WAIT. It does not let two live servers share a port; that is SO_REUSEPORT on systems that support it. |
| Why do you need framing on top of TCP? | Byte stream | TCP delivers bytes, not messages, so one write can arrive in pieces or merged with the next. Protocols add a length prefix or a delimiter and read until the full message is in. |
| What is the delayed ACK, and how does it interact with small writes? | Latency | Receivers may wait briefly to combine ACKs with outgoing data. A sender that holds small writes until an ACK arrives then waits for that delay, which shows up as steady extra latency on request-response traffic. |
Throughput, MTU and fragmentation
Slow transfers on fast links are a favorite senior question because the answer is arithmetic. If the window is smaller than the bandwidth-delay product, the sender spends most of each round trip waiting.
# Bandwidth-delay product: how many bytes must be in flight to fill the path
link_bps = 1_000_000_000 # 1 Gbit/s
rtt_s = 0.080 # 80 ms round trip
bdp_bytes = link_bps / 8 * rtt_s
print(int(bdp_bytes)) # 10000000: about 10 MB in flight
# Without window scaling the window field tops out at 65,535 bytes
max_throughput = 65_535 / rtt_s * 8
print(round(max_throughput / 1e6, 1)) # 6.6 Mbit/s, whatever the link speed
# Sequence numbers are 32-bit and wrap, so compare them modulo 2**32
def seq_after(a, b):
return ((a - b) & 0xFFFFFFFF) < 0x80000000 and a != b
print(seq_after(5, 4_294_967_290)) # True: 5 comes after a number near the top- What happens when a packet is larger than the next link's MTU? In IPv4 a router may fragment it unless the Don't Fragment bit is set. With DF set, or always in IPv6, the router drops it and returns an ICMP message saying the packet is too big and what size fits.
- What is path MTU discovery, and how does it break? The sender sets DF and lowers its packet size when "too big" messages come back. If a firewall blocks those ICMP messages, large packets vanish silently while small ones work: the classic MTU black hole.
- Why is fragmentation avoided? Losing one fragment loses the whole packet, reassembly costs memory, middleboxes often drop fragments, and only the first fragment carries port numbers for firewalls to inspect.
- What is MSS clamping? A router or VPN gateway rewrites the MSS option in SYN packets to a smaller value, so both ends send segments that fit inside the tunnel's reduced MTU.
- Why can one long-distance transfer be slow while many parallel ones fill the link? Each connection is limited by its own window and its own reaction to loss. Several streams together keep more data in flight, which is why some transfer tools open parallel connections.
- How do loss and RTT limit a single TCP flow? For loss-based congestion control, throughput falls as round-trip time and loss rate rise, so a small loss rate on an intercontinental path hurts far more than the same loss on a LAN. Delay-based algorithms such as BBR react differently, which is worth naming.
Senior and scenario questions
| Scenario | What it tests | What a strong answer shows |
|---|---|---|
| Clients see "connection refused" for some requests and timeouts for others. What is the difference? | Symptom reading | Refused means a RST came back fast: the host is up but nothing listens, or the accept queue overflowed. A timeout means no answer at all: a firewall drop, a routing problem or a dead host. Each points to a different layer. |
| Small API calls work over the VPN but file uploads hang. | MTU | Suspect a path MTU black hole. Test with pings of growing size and DF set, check whether ICMP "too big" messages are filtered, and fix with MSS clamping or by allowing that ICMP. |
| Long-lived connections through a load balancer reset after a few minutes of quiet. | Idle timeouts | The balancer's idle timeout expired and dropped state; the next packet gets a RST. Match application heartbeats or TCP keepalive intervals to the shortest idle timeout on the path. |
| A service making many outbound calls fails with "cannot assign requested address". | Port exhaustion | Ephemeral ports to one destination are used up, often by sockets waiting in TIME_WAIT. Reuse connections with a pool or keep-alive, and only then consider widening the port range. |
| Captures show many retransmissions between two data centers. | Loss analysis | Check whether retransmits cluster on one path, interface errors and drops on switches, and buffer overruns. Distinguish real loss from reordering, which can also trigger duplicate ACKs. |
| A server is flooded with SYNs from spoofed addresses. | Attack handling | Confirm with SYN_RECEIVED counts, make sure SYN cookies are on, raise the queue limits, and push filtering upstream to a provider or scrubbing service if volume exceeds the link. |
| Should this internal RPC move from TCP to QUIC? | Judgment | QUIC avoids head-of-line blocking across streams and has faster connection setup, but runs in user space and is harder to inspect with existing tools. For low-loss data center traffic the gain may be small; measure first. |
# Count sockets by TCP state, then list the ones stuck in CLOSE_WAIT
ss -tan | tail -n +2 | cut -d' ' -f1 | sort | uniq -c
ss -tanp state close-wait
# Per-connection internals: RTT, congestion window, retransmits
ss -ti dst 198.51.100.7
# Only SYN and RST packets, numeric addresses and ports
tcpdump -nn -i any 'tcp[tcpflags] & (tcp-syn|tcp-rst) != 0'
# Path MTU test: 1472 bytes of payload + 28 bytes of headers = 1500, Don't Fragment set
ping -M do -s 1472 198.51.100.7Fictional example
- Interviewer
- Staff at one branch can browse the internal portal, but uploading a file over about a megabyte hangs and eventually fails. Everyone else is fine. Where do you start?
- Candidate
- Small requests work and large ones hang, from one site only, so I suspect packet size before application bugs. The branch connects through a VPN tunnel, which lowers the usable MTU. I would capture on the server side and look for the client's full-size segments never arriving while the small ones do. Then from a branch machine I would ping the server with Don't Fragment set, starting at 1,472 bytes of payload and stepping down until replies come back, to find the real path MTU.
- Interviewer
- Suppose the working size is 1,400. What is your fix?
- Candidate
- Short term, clamp the MSS on the tunnel so new connections negotiate segments that fit. Long term, find where ICMP "too big" messages are being filtered and allow them, because path MTU discovery should have handled this without help. I would also confirm the fix with a fresh capture rather than closing the ticket on the first successful upload.
A ten-day TCP/IP study plan
- Days 1 and 2: draw the IPv4, IPv6 and TCP headers from memory and say what every field does.
- Day 3: the state machine. Draw it, then explain CLOSE_WAIT, TIME_WAIT and SYN_RECEIVED pile-ups in one sentence each.
- Day 4: retransmission, fast retransmit and SACK. Walk through one lost segment step by step.
- Day 5: window arithmetic. Compute bandwidth-delay products for three links and the throughput ceiling for a fixed window.
- Day 6: MTU, MSS, fragmentation and path MTU discovery, with the black hole story ready to tell.
- Day 7: open a capture file in Wireshark and find the handshake, a retransmission and a reset. Read the TCP flags aloud.
- Day 8: write a small socket client and server on your own machine with a length-prefixed message format.
- Days 9 and 10: mock scenario rounds: refused versus timed out, idle resets, port exhaustion and slow transfers.
For the wider survey of layers, HTTP versions and TLS, read computer networks interview questions. Name resolution has its own page: DNS interview questions. Router and switch configuration belongs to network engineer interview questions.
Scenario rounds are judged on how you reason aloud, so practice them spoken rather than written. Natively, an AI interview assistant for Mac and Windows, can transcribe a mock troubleshooting round on your computer and keep the transcript and notes, so you can check whether you named the evidence before the conclusion. In practice it can read a packet diagram, a capture screenshot or a socket error from your screen and suggest what to look at next. With Pro or the free trial it can also use your résumé and the job description you add.
Questions people ask
What TCP/IP questions are asked in interviews?
Expect the purpose of IP and TCP header fields, TTL and traceroute, MTU versus MSS, the TCP state machine, CLOSE_WAIT and TIME_WAIT, retransmission and SACK, window scaling, and scenario questions on timeouts, resets and slow transfers.
What does CLOSE_WAIT mean in a TCP interview question?
The remote side closed the connection and your application has not closed its own socket yet. A large and growing number usually points to a connection leak in the application code.
How do I answer TCP/IP troubleshooting questions?
Start from the symptom, say what evidence you would collect, such as socket states or a packet capture, and explain what each result would rule in or out before naming a fix.
Are TCP/IP questions asked for freshers?
Yes, at the level of layers, ports, the handshake, TTL and MTU. Experienced and SRE candidates get the state machine, congestion and window arithmetic, and capture-reading scenarios.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
