Interactive Traffic: Delayed ACKs, the Nagle Algorithm and TCP_NODELAY
How TCP handles small writes and interactive traffic: delayed acknowledgments, the Nagle algorithm, the 40 ms stall that appears when the two meet in a write-write-read pattern, and how TCP_NODELAY, TCP_QUICKACK and TCP_CORK change it, measured in the lab.
kvi5hnuCode Sprout team member11 min readOn this page
Bulk transfers send full-size segments as fast as the window allows. Interactive traffic is different: keystrokes in a remote shell, small RPC (remote procedure call) requests, game updates, a database query and its short answer. Here, many segments carry only a few bytes, and the per-packet overhead matters more than the bytes. TCP has two old mechanisms to cut that overhead: the receiver delays ACKs, and the sender holds back small segments (the Nagle algorithm). Each is sensible on its own. Together, they can add tens of milliseconds to every request, which is why so many programs turn Nagle off.
The lab path in this article has an RTT of about 4 ms:
rtt min/avg/max/mdev = 3.798/4.215/4.550/0.269 ms
Delayed acknowledgments
A receiver doesn't have to ACK each segment immediately. If it waits a little, the ACK can ride along with reply data (piggybacking), or one ACK can cover two segments. RFC 1122 (repeated in RFC 9293) allows this with two limits: the delay must be less than 0.5 seconds, and in a stream of full-size segments, at least every second one must be ACKed.
Linux delays ACKs adaptively. The delay starts at 40 ms and is capped at 200 ms (the kernel's TCP_DELACK_MIN and TCP_DELACK_MAX). It also has a quick-ACK mode, used at the start of a connection and whenever the receiver thinks the sender needs ACKs to make progress, in which it ACKs every segment at once. And it switches into an interactive ("ping-pong") mode when it sees request-response traffic, because there an ACK can usually wait for the reply.
The lab sent 15 messages, 250 ms apart, to three receivers that never replied, replied once, or replied once and then set TCP_QUICKACK:
receiver never sends data:
message 1 ( 100 bytes): ACK after 0.01 ms
message 2 ( 100 bytes): ACK after 0.06 ms
message 3 ( 100 bytes): ACK after 0.04 ms
message 4 ( 100 bytes): ACK after 0.03 ms
message 5 ( 100 bytes): ACK after 0.04 ms
message 6 ( 100 bytes): ACK after 0.05 ms
message 7 ( 100 bytes): ACK after 0.02 ms
message 8 ( 100 bytes): ACK after 0.02 ms
message 9 ( 100 bytes): ACK after 0.06 ms
message 10 ( 100 bytes): ACK after 0.05 ms
message 11 ( 100 bytes): ACK after 0.06 ms
message 12 ( 100 bytes): ACK after 0.07 ms
message 13 (2896 bytes): ACK after 0.04 ms
message 14 (2896 bytes): ACK after 0.06 ms
message 15 (2896 bytes): ACK after 0.06 ms
receiver replied once to message 1:
message 1 ( 100 bytes): ACK after 0.00 ms
message 2 ( 100 bytes): ACK after 49.90 ms
message 3 ( 100 bytes): ACK after 0.07 ms
message 4 ( 100 bytes): ACK after 0.07 ms
message 5 ( 100 bytes): ACK after 0.05 ms
message 6 ( 100 bytes): ACK after 0.06 ms
message 7 ( 100 bytes): ACK after 0.06 ms
message 8 ( 100 bytes): ACK after 0.06 ms
message 9 ( 100 bytes): ACK after 0.06 ms
message 10 ( 100 bytes): ACK after 0.06 ms
message 11 ( 100 bytes): ACK after 0.05 ms
message 12 ( 100 bytes): ACK after 0.07 ms
message 13 (2896 bytes): ACK after 0.06 ms
message 14 (2896 bytes): ACK after 0.06 ms
message 15 (2896 bytes): ACK after 0.05 ms
receiver replied once, then set TCP_QUICKACK before every read:
message 1 ( 100 bytes): ACK after 0.01 ms
message 2 ( 100 bytes): ACK after 0.05 ms
message 3 ( 100 bytes): ACK after 0.06 ms
message 4 ( 100 bytes): ACK after 0.05 ms
message 5 ( 100 bytes): ACK after 0.06 ms
message 6 ( 100 bytes): ACK after 0.08 ms
message 7 ( 100 bytes): ACK after 0.01 ms
message 8 ( 100 bytes): ACK after 0.03 ms
message 9 ( 100 bytes): ACK after 0.07 ms
message 10 ( 100 bytes): ACK after 0.06 ms
message 11 ( 100 bytes): ACK after 0.10 ms
message 12 ( 100 bytes): ACK after 0.07 ms
message 13 (2896 bytes): ACK after 0.08 ms
message 14 (2896 bytes): ACK after 0.08 ms
message 15 (2896 bytes): ACK after 0.08 ms
The receiver that never sent data stayed in quick-ACK behavior and ACKed every message within a fraction of a millisecond. The one that replied to message 1 switched to interactive mode, and the ACK for message 2 waited for the delayed-ACK timer, about 40 to 50 ms, hoping for a reply that never came. When that timer fires in interactive mode, Linux concludes that it guessed wrong, leaves interactive mode, and resets the delay to its minimum. Each later message then arrived after a pause longer than the RTO, which puts a receiver that isn't in interactive mode back into quick-ACK mode, so messages 3 onward were ACKed at once again. The third receiver set TCP_QUICKACK before each read and never delayed. On Linux, this option isn't permanent: the kernel can clear it, so programs that rely on it set it again after each recv().
The Nagle algorithm
The Nagle algorithm (RFC 896, 1984; that RFC is now Historic, but the rule itself is required by RFC 1122 and carried into RFC 9293) targets the sender. Its rule:
If there is unacknowledged data in flight, don't send a segment smaller than the MSS. Buffer it until either an ACK arrives or enough data accumulates for a full segment.
So a connection has at most one small segment outstanding at a time. A user typing in a remote shell over a slow link sends the first keystroke at once, then collects the following keystrokes while waiting for the ACK, and sends them together. On a fast link, ACKs come back so quickly that Nagle has almost no effect. On a slow one, it can cut the packet count dramatically. Linux implements a variant (Minshall's) that counts only small unacknowledged segments, so full-size segments in flight don't hold back the tail of a write.
When the two meet
The trouble starts with a common application pattern: write, write, read. A client writes a request in two pieces, such as a header and then a body, and waits for the reply:
- The header is sent immediately, because nothing is outstanding.
- The body is small and the header is unacknowledged, so Nagle holds it.
- The server has only the header, so it can't reply yet. Its ACK is delayed, waiting for a reply.
- Nothing moves until the server's delayed-ACK timer fires. The ACK releases the body, and the reply follows.
The ladder diagram below draws these four steps next to the same exchange with Nagle turned off.

The lab ran 30 such requests, a 10-byte write then a 100-byte write, with Nagle on and then with TCP_NODELAY:
Nagle on (default) median 52.52 ms min 7.82 ms max 57.51 ms (30 requests)
TCP_NODELAY median 4.10 ms min 3.03 ms max 4.66 ms (30 requests)
The plot below shows every one of the 30 requests as a dot.

Over a 4 ms path, each request took about 50 ms with Nagle, more than ten times longer than without it. The capture of one request with Nagle on shows the stall. In each line, seq and ack are relative sequence numbers, and len is the bytes of data; len=0 is a bare ACK:
+0.00 ms client seq=221 ack=201 len=10
+45.09 ms server seq=201 ack=231 len=0
+45.10 ms client seq=231 ack=201 len=100
+49.01 ms server seq=201 ack=331 len=0
+49.02 ms server seq=201 ack=331 len=100
+49.03 ms client seq=331 ack=301 len=0
The 10-byte header went out, the server's ACK came back about 45 ms later, and only then did the client send the 100-byte body. (The first request was fast because the server was still in quick-ACK mode.) With TCP_NODELAY, both writes left together (the last line is the start of the next request):
+0.00 ms client seq=331 ack=301 len=10
+0.05 ms client seq=341 ack=301 len=100
+3.84 ms server seq=301 ack=441 len=0
+3.85 ms server seq=301 ack=441 len=100
+3.86 ms client seq=441 ack=401 len=0
+64.45 ms client seq=441 ack=401 len=10
TCP_NODELAY, TCP_CORK and writing well
There are several ways out:
TCP_NODELAYturns Nagle off for a socket. Every write is sent as soon as the window allows. Most latency-sensitive software sets it: SSH for interactive sessions, many HTTP clients and servers, database drivers, RPC frameworks. Go sets it on TCP connections by default.- Write the whole message at once. Building the request in a buffer, or using
writev()/sendmsg()with several pieces, means there's only one small write, so Nagle never holds anything. This is the best fix, because it also saves system calls and packets. TCP_CORK(Linux) does the opposite ofTCP_NODELAY: it holds all partial segments, even with nothing in flight, until the cork is removed or a full segment builds up (with a 200 ms ceiling). A server can cork, write headers,sendfile()the body, and uncork, so the response leaves in full segments.MSG_MOREon a singlesend()gives the same hint per call. Linux also does a mild version on its own: with autocorking (net.ipv4.tcp_autocorking = 1, the default), consecutive small writes are merged while an earlier packet of the same connection is still waiting in the local transmit queue.TCP_QUICKACKon the receiving side makes the peer's delayed ACK problem go away, but it must be re-armed and affects only the receiver's ACKs.
Turning Nagle off means each small write becomes its own packet. If an application writes one byte at a time with TCP_NODELAY, it sends a 41-byte (or larger) packet per byte. Disable Nagle and write whole messages.
Interactive traffic in captures
A remote shell session shows the classic pattern: the client sends a 1-byte keystroke, the server echoes it back with its ACK piggybacked, and the client ACKs the echo, often delayed and combined with the next keystroke. Each keystroke can cost two or three packets, which is exactly the overhead the Nagle algorithm and delayed ACKs were designed to reduce. Modern SSH sets TCP_NODELAY for interactive sessions, so each keystroke goes out at once, and also pads keystroke timing to make them harder to analyze.
Common questions
Should I always set TCP_NODELAY?
For request-response protocols where latency matters, usually yes, as long as the application writes whole messages. For bulk transfers it makes no difference, since full segments aren't held back. Where it hurts is code that makes many tiny writes: there, Nagle was quietly saving packets.
Why is the stall about 40 ms and not 200 ms?
That's Linux's minimum delayed-ACK time. The delay adapts between 40 and 200 ms. Some other systems use a fixed delay, up to 200 ms, so the same program can stall longer against them.
Can I turn off delayed ACKs on Linux?
Not globally with a sysctl. Per socket, TCP_QUICKACK disables them until the kernel decides otherwise, so it has to be set again after reads. A route option, ip route ... quickack 1, does it for all connections using that route.
Does Nagle affect the first write on a connection?
No. With nothing in flight, the first small segment is sent immediately. Nagle holds only a later small segment while an earlier one is unacknowledged.
What's the difference between TCP_CORK and Nagle?
Nagle holds small segments only while data is unacknowledged. TCP_CORK holds partial segments regardless, until the application uncorks. Cork is a deliberate "more is coming" signal. Nagle is an automatic heuristic.
Summary
- Receivers delay ACKs, on Linux between 40 and 200 ms, to piggyback them on replies or cover two segments. Linux ACKs immediately in quick-ACK mode and delays in interactive mode. In the lab, one reply switched the receiver to delaying, and a single missed guess switched it back.
- The Nagle algorithm allows only one small unacknowledged segment at a time, collecting further small writes until an ACK arrives.
- Together, with a write, write, read pattern, they stall each request until the delayed ACK fires. In the lab, requests over a 4 ms path took about 50 ms with Nagle and about 4 ms with
TCP_NODELAY. - Fix it by writing whole messages at once (buffers or
writev()), and setTCP_NODELAYfor latency-sensitive protocols.TCP_CORKandMSG_MOREdeliberately batch output.TCP_QUICKACKaffects the receiver's ACKs and must be re-armed.
Practice questions
1. A client sends a 20-byte request in one write and waits for a 500-byte reply. Will Nagle or delayed ACK slow it down?
Answer
No. The single write is sent at once because nothing is in flight. The server's ACK is delayed, but it rides along with the reply, which goes out as soon as the server writes it. Only multiple small writes before a read run into the stall.
2. A program writes a 5-byte header, a 5-byte length field and a 50-byte body as three separate writes, then reads the reply. With Nagle on and a 40 ms delayed-ACK peer, roughly how long does a request take over a 10 ms RTT path?
Answer
The header goes out at once. The length and body are held together until the delayed ACK arrives, about 40 ms after the header reached the server, and they then go out as one segment. The reply comes back one round trip after that. So about 5 + 40 + 10 + 5 = 60 ms, instead of about 10 ms.
3. Why does setting TCP_NODELAY on a program that writes one byte at a time make things worse for the network?
Answer
Each byte becomes its own segment, carrying at least 40 bytes of IP and TCP headers (more with options). The packet count and header overhead explode. Nagle would have combined the bytes while waiting for ACKs. The fix is to buffer in the application and write whole messages.
4. A web server writes response headers with write() and the body with sendfile(). Why might it use TCP_CORK?
Answer
Without corking, the headers may leave as a small segment of their own, before the body. With the socket corked, the headers and the start of the body fill full-size segments, and uncorking flushes the remainder. It saves a packet per response and avoids a small first segment.
5. In the lab, the receiver that replied once delayed its ACK for message 2 but not for message 3. Why?
Answer
After replying to message 1, it switched to interactive mode, so it delayed the ACK for message 2 expecting a reply. No reply came, and the delayed-ACK timer fired. In interactive mode, Linux treats that as a wrong guess: it leaves interactive mode and resets the delay to its minimum. Out of interactive mode, a message arriving after a pause longer than the RTO switches the receiver to quick-ACK mode, so later messages, 250 ms apart, were ACKed immediately again.
Previous: Spurious Retransmissions, Reordering and Duplication: DSACK, Eifel and F-RTO
Next: TCP Flow Control: The Sliding Window, Zero Windows and Silly Window Syndrome

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.