Networking foundations: IP, TCP, UDP and QUIC

Reading: 49 min, plus 17 in closed details. Data as of October 2026; measured on a real path and on loopback. Child of Topic: protocols.

The idea in one screen

Every byte you send rides in an IP packet that may be lost, and TCP turns those packets into a reliable stream by numbering bytes, waiting for acknowledgements and never having more than one window unacknowledged, so one connection moves at most one window per round trip. Almost every slow transfer, stalled token stream or hung training job traces back to that sentence, or to one of the boxes that rewrite or drop packets on the way.

Each layer adds one header and one promise; a streamed token pays 52 bytes of header for 124 of data. Fig. 1 follows one token down the server's stack, across two routers and up the client's.

  1. The server writes one token. Token 1 of the running stream is 124 bytes on the wire as a Server-Sent Event (recorded by the root page). The program hands them to its socket and is done; everything below is the kernel's.
  2. TCP adds 20 bytes, usually 32. The two ports, the byte numbers, the acknowledgement and the window (sections 2 to 7); the timestamp option makes it 32. UDP would carry only ports, length and checksum, in 8 (section 11).
  3. IP adds 20 bytes. The two addresses and the hop counter (section 1): 124 + 32 + 20 = 176 bytes on the wire, 30% of them header.
  4. Routers read only the IP header. Each hop looks up the destination address, decrements the hop counter and forwards. Nothing on the path needs the TCP header or the data; the boxes that read them anyway are the trouble of sections 9 and 12.
  5. The client's kernel unwraps it. IP hands the segment to the socket its 5-tuple names; TCP puts the bytes in order and sends an acknowledgement back; the program reads 124 bytes. Loss, windows and timers (sections 4 to 7) all live in this layer.
  6. The link only sets the size limit. To scale: a full segment of a checkpoint download is 1,448 bytes of data (one MSS) plus the same 52 bytes of headers, exactly the 1,500-byte MTU of standard Ethernet (section 10); the token's packet leaves room for 1,324 bytes more, unused.

You need nothing beyond what an engineer who has called an HTTP API knows. The overview of one LLM request through every layer is section 4 of Topic: protocols; this page is the depth under it. The running example is that root's streaming request: 277 bytes up, then Server-Sent Events, one small write per token about 50 ms apart. Later sections scale it up to the transfer that hurts most in ML work, a checkpoint of hundreds of gigabytes across a long path.

Packet, segment, datagram
an IP unit; a TCP unit inside it; a UDP unit inside it
RTT
round-trip time: a packet there and the answer back
Window
bytes a TCP sender may have in flight without an acknowledgement
BDP
bandwidth-delay product, link rate × RTT: the window needed to fill a path
MTU, MSS
largest IP packet a link carries; largest TCP payload per segment
5-tuple
protocol, source address and port, destination address and port: a connection's name
IPTCPUDPQUIC
Gives youan address for every machine; packets forwarded hop by hopa reliable, ordered, flow- and congestion-controlled byte stream between two socketsports and a checksum on single messagesreliable, encrypted, independent streams in one connection, plus unreliable datagrams if wanted
Costsnothing guaranteed: loss, reordering, duplicatesone round trip to open; head-of-line blocking; one stream capped at window / round tripyou write reliability and pacing yourselfuser-space CPU; UDP blocked on some networks
Header20 bytes (IPv4, no options), 40 (IPv6)20 bytes, usually 32 with timestamps8 bytesafter the first packets, a short header (1 flag byte, a 0 to 20 byte connection ID, a 1 to 4 byte packet number, RFC 9000 s17.3.1), inside UDP's 8
Defined inRFC 791 (1981), RFC 8200 (2017)RFC 9293 (2022, replaces RFC 793)RFC 768 (1980)RFC 9000, 9001, 9002 (2021); v2 RFC 9369
Where you meet itVPC subnets, pod IPs, MTU limitsevery HTTP/1.1 and HTTP/2 call, gRPC, torch.distributed rendezvous, S3 uploadsDNS, NTP, RoCEv2 between GPUsHTTP/3 to browsers and CDNs

Not here: name lookup (DNS), encryption (TLS and certificates), request semantics (HTTP), SSH, GPU fabrics (Interconnects and scaling) and the event loop that serves many sockets (Concurrency). Labels: measured here, illustrative, derived (with its formula).

Where and how this page measured (provenance)

measured marks what was run for this page on 5 October 2026 on an Apple M1 Pro laptop (macOS 27.0.1, Python 3.13.5, aioquic 1.3.0) on a home broadband line, on loopback or against public test endpoints; illustrative marks a picture of a shape rather than data; derived numbers show their formula. Linux behaviour is taught from the kernel source and documentation.

Twelve numbers worth remembering (each links to its section)

1. IP: addresses, prefixes and the path

IP gives every network interface an address, puts source and destination on every packet, and lets each router forward it one hop closer. That is the whole promise: a packet can be dropped, duplicated, delayed or overtaken, and IP says nothing (RFC 791 s1.2: a datagram service with no reliability mechanisms).

An IPv4 address is 32 bits (192.0.2.7); an IPv6 address is 128 bits in hex groups, the longest run of zero groups shortened to :: (2001:db8::7). Addresses are handed out as prefixes in CIDR notation (RFC 4632): 10.0.0.0/16 is every address whose first 16 bits match, 232−16 = 65,536 addresses. A VPC is a prefix, its subnets are longer prefixes inside it, and a router's table is a list of prefixes with a next hop each; the longest matching prefix wins.

Three reserved blocks cause most address incidents in ML infrastructure:

  • Private ranges 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 (RFC 1918) are reused inside every company, VPC, Docker bridge and Kubernetes cluster. Two networks that both picked 10.0.0.0/16 cannot be peered or joined by VPN without renumbering one: the router cannot tell which 10.0.3.4 you mean.
  • Shared address space 100.64.0.0/10 (RFC 6598) is for carrier-grade NAT, and some Kubernetes and overlay setups also use it, so they collide.
  • Link-local 169.254.0.0/16 (RFC 3927) never leaves the link; clouds put the instance metadata service at 169.254.169.254 (AWS IMDS), so an agent that can fetch arbitrary URLs from a VM can read that VM's credentials (server-side request forgery; the DNS page covers the rebinding variant).

IPv6 has a private block too, unique local addresses fc00::/7 (RFC 4193), but its point is that every device can have a global address and NAT (section 9) is not needed. When a name has both an IPv6 (AAAA) and an IPv4 (A) address, clients race them with Happy Eyeballs (RFC 8305): prefer IPv6, start IPv4 if it has not connected within a short delay (250 ms recommended), keep the winner. A broken IPv6 path therefore costs a quarter of a second per connection, not a failure.

Two prefixes either nest or collide. Type a VPC, pod range or peer's subnet and a second prefix. Predict first: can 10.0.0.0/8 and 10.100.0.0/16 be peered? Try 100.64.0.0/10 and 172.31.0.0/16 (the AWS default VPC) too.
traceroute is TTL 1, 2, 3 and each router naming itself as it drops the probe. illustrative path, documentation addresses

Hop by hop: TTL, ICMP and traceroute

Every IPv4 packet carries a time to live (TTL; in IPv6 the hop limit) that each router decrements; at zero the router drops it and returns an ICMP "time exceeded" (ICMP is IP's control-message protocol: errors, and echo, which is ping). That stops a routing loop from circulating a packet forever, and it is how traceroute and mtr map a path. ICMP also carries the "packet too big" signal section 10 depends on, which is why "block all ICMP" breaks things.

  1. Send probes with TTL 1, 2, 3 and so on. Each router subtracts one before forwarding; whoever brings it to zero drops it and says so.
  2. TTL 1 dies at the first router. The home router decrements 1 to 0, drops the probe and sends ICMP "time exceeded" from its own address: line 1 of the output is 192.0.2.1.
  3. TTL 2 dies one hop further. The first router forwards it with TTL 1; the ISP router takes it to 0 and replies. Each line of traceroute is a different probe, so the hops can come from different paths.
  4. TTL 3: the transit router names itself. Each reply also gives a round-trip time to that hop. A router that is busy may answer ICMP slowly or not at all, which shows as * without any loss to real traffic.
  5. TTL 4 reaches the server. The probe arrives with TTL 1 left; the destination answers instead of a router (an echo reply, or "port unreachable" for UDP probes), and traceroute stops. mtr repeats this continuously and counts loss per hop: loss that starts at a hop and continues to the end is real.
IPv4 against IPv6, dual-stack share, how addressing fails (depth)
IPv4 (RFC 791)IPv6 (RFC 8200)
Address32 bits, about 4.3 billion, exhausted128 bits
Header20 bytes without options, with a header checksum40 bytes fixed, no header checksum, options moved to extension headers
Fragmentationrouters may split a packet unless the Don't Fragment bit is setrouters never fragment; only the sender may, so path MTU discovery is mandatory in practice
Smallest MTU every link must carry68 bytes (RFC 791)1,280 bytes (RFC 8200 s5)

Dual stack is the normal case. Google's share of users reaching it over IPv6 first crossed 50 percent on 28 March 2026 (50.10 percent) and stood at 51.69 percent on 3 October 2026, the latest point in its published data (fetched 5 October 2026; weekends run higher than weekdays).

How it fails. Overlapping prefixes (peering refused, or traffic silently going to the wrong network): compare route tables with ip route (Linux) or netstat -rn (macOS), and plan VPC ranges before the first cluster. No route at all: "Network is unreachable" instantly. Loss at one hop: mtr host shows loss per hop; loss that starts at one hop and continues to the end is real, loss at one hop only is usually that router de-prioritising ICMP.

2. Ports, sockets and the 5-tuple

An address picks a machine; a port (16 bits, 0 to 65,535) picks the program. A socket is the operating system's handle for one end of a conversation: your code reads and writes it, the kernel runs the protocol. Servers listen on a well-known port (443 for HTTPS, 22 for SSH, 29500 by convention for torch.distributed's rendezvous); the client's kernel picks a temporary ephemeral port for its end. A TCP connection is named by its 5-tuple, and the kernel at each end uses it to find the socket for every arriving packet.

Three consequences follow from the picture. Section 3 shows how TIME_WAIT turns the port count into a rate limit. Anything that rewrites addresses or ports (NAT, section 9; a load balancer) must keep a table keyed on the 5-tuple, and that table fills and forgets. And changing any element ends a TCP connection: a laptop moving from Wi-Fi to a phone hotspot gets a new address and every TCP connection on it dies, while QUIC survives the move (section 12 records it).

Only the client's port varies, so one client address has a few tens of thousands of connections to one server port

Three connections from one client to one HTTPS server: the protocol, both addresses and the server's port are the same, and the ephemeral source port is the only thing that tells them apart. The ephemeral range is 32,768 to 60,999 on Linux, 28,232 ports (ip-sysctl docs), and 49,152 to 65,535 on this Mac, 16,384 ports (measured sysctl net.inet.ip.portrange, the IANA dynamic range of RFC 6335).

Server

socket() → bind(addr, port) → listen(backlog) → loop: accept() returns a new socket per client → recv/send → close()

Client

socket() → connect(addr, port) (the kernel picks the ephemeral port and runs the handshake) → send/recv → close()

Which address the server binds matters. 127.0.0.1 (loopback) accepts only from the same machine; 0.0.0.0 (or ::) accepts on every interface. A model server bound to 127.0.0.1 inside a container is unreachable from outside even with the port published, and the client sees "connection refused" (the root's Failure lab case "Connection refused" shows the exact error text of curl, requests, httpx and Node). The reverse mistake, a notebook on 0.0.0.0 on a machine with a public address, exposes it to the internet. How one process serves thousands of sockets at once (epoll, kqueue, the event loop) is the Concurrency page's.

A TCP socket is a stream, not a list of messages

TCP promises the bytes and their order, not where your writes started and ended; UDP keeps each datagram whole. measured on loopback, three writes of token-000n, reader started after the writes:


So every protocol on TCP has framing: HTTP/1.1 uses Content-Length or chunk sizes, Server-Sent Events use blank lines, gRPC and HTTP/2 put a length in front of each frame. Code that assumes "one recv equals one message" passes every test on loopback and fails under load or on a real network, where segments split and merge differently.

See it yourself (commands)

lsof -nP -iTCP -sTCP:ESTABLISHED (macOS and Linux) or ss -tnp (Linux) lists each connection's 5-tuple and owning process; lsof -nP -iTCP:8000 -sTCP:LISTEN shows who listens on a port and on which address.

3. A connection's life, and why round trips are the unit of latency

Opening: the three-way handshake. TCP numbers every byte. Each side picks a random initial sequence number (random so an attacker off the path cannot guess it and inject data, RFC 9293 s3.4.1): the client sends SYN ("my bytes start at x"), the server SYN-ACK ("mine start at y; I expect x+1"), the client ACK, with data allowed on that third segment. So a new connection costs exactly one round trip before the request leaves. measured: connect() to Cloudflare's speed-test host took 14.1 to 19.4 ms over twelve connections, against a ping round trip of 14.0 to 18.4 ms to Cloudflare's resolver: one round trip, as predicted.

Closing, and the states in between

Each direction closes separately: the side that has finished sending sends FIN, the other acknowledges, and a half-close is allowed (send the whole request, shut the sending side, keep reading). RST (reset) is the abrupt alternative, "this connection does not exist for me": a kernel sends it for a segment that matches no socket (a refused connection, a NAT that forgot the mapping), and an application forces one by closing with unread data.

Two of these states cause most production tickets; ss -tan (Linux) or netstat -an -p tcp (macOS) prints their names. CLOSE_WAIT piling up means your program received the peer's FIN but never called close() (a leak in your code, not the network); TIME_WAIT piling up means you open and close connections faster than you should. Fig. 2 walks the running request through both kernels:

  1. Before anything. The server has called socket(), bind() and listen(): its kernel now answers SYNs on port 443. The client has no socket yet.
  2. connect(): SYN. The client kernel picks an ephemeral port and a random initial sequence number x, and offers its options (MSS, window scale, SACK, timestamps). They can only be agreed now.
  3. SYN-ACK. The server picks its own sequence number y, acknowledges x+1 and answers with its options. The half-open connection waits in the SYN queue.
  4. ACK, and the request rides along. One round trip after connect() started, both ends are ESTABLISHED and the 277-byte request is on its way. The connection moves to the accept queue until the server calls accept() (section 8). Over HTTPS, the TLS handshake comes first.
  5. The response streams. A 244-byte head, then one small write per token, each segment acknowledged. Sections 4 to 7 are everything that can go wrong here.
  6. Server closes first. The running request asked for Connection: close, so after the last event the server calls close(): its kernel sends FIN, "no more data from me", and enters FIN_WAIT_1.
  7. The client acknowledges; its program has not closed yet. The client kernel acknowledges and the socket enters CLOSE_WAIT: the peer is done, and it is now up to the client program to call close(). A socket stuck here forever is a bug in the program, not the network.
  8. The client closes. The program reads the end of the stream and closes: its FIN goes out and it waits in LAST_ACK for the final acknowledgement.
  9. The last ACK. The client is done. The server, which closed first, enters TIME_WAIT: it keeps the 5-tuple reserved for 2 MSL so a delayed old segment cannot leak into a new connection, and it can resend this ACK if it is lost.
  10. TIME_WAIT expires. After 60 s on Linux (30 s on this Mac) the entry is gone. The eleventh state, CLOSING, happens only when both sides send FIN at the same moment.

The round-trip budget of one request

Light in fibre covers about 200,000 km per second (refractive index about 1.5), so New York to London, 5,585 km, can never take less than a 56 ms round trip (High Performance Browser Networking, chapter 1, table 1-1). Every protocol step that waits for an answer costs one of those.

That is why connection reuse matters more the farther away the API is, and why the root's On the wire tab measures cold, resumed and reused connections.

A fresh HTTPS connection pays three round trips before the first response byte; a pooled one pays one. Predict how much a connection pool saves on a 160 ms path, then move the round trip. derived: TCP 1 RTT, TLS 1.3 1 RTT (TLS), request and first byte 1 RTT; QUIC combines transport and TLS in one (section 12). Server time and DNS are left out.

TIME_WAIT, and why closing fast runs out of ports

The side that closes first holds the connection in TIME_WAIT for twice the maximum segment lifetime (2 MSL), so a delayed duplicate of an old segment cannot be mistaken for data in a new connection on the same 5-tuple, and so it can resend a lost final ACK (RFC 9293 s3.6). Linux fixes it at 60 seconds (TCP_TIMEWAIT_LEN (60*HZ) in include/net/tcp.h; not a sysctl).

new connections per second to one destination ≤ ephemeral ports / TIME_WAIT = 28,232 / 60 s ≈ 470 per second
28,232
ports in Linux's default range 32,768 to 60,999
60 s
Linux TIME_WAIT; the limit applies per (source address, destination address, destination port)

A client that opens a fresh connection per request (no connection pool, an embedding API called in a tight loop, a health checker) hits that wall with EADDRNOTAVAIL ("Cannot assign requested address"). The fix is reuse: a pool with keep-alive, which also saves the round trips above. Whoever closes first holds TIME_WAIT, so a server that closes idle client connections collects them too.

When the SYN gets no answer (a firewall, a security group, a host that is down) the client retries with exponential backoff; Linux's default of 6 retries gives up after about 131 seconds (tcp_syn_retries). A connect with no timeout of its own can hang for two minutes, so every client needs an explicit connect timeout, much shorter than its read timeout. The root's Failure lab records five clients' errors for "Connect timeout" against an address that never answers, and for "Connection refused" the contrast: an RST back in under a millisecond.

Options agreed in the SYN, TIME_WAIT on macOS, the reuse knobs (depth)

The SYN negotiates options that can never be added later (RFC 9293 s3.2, RFC 7323, RFC 2018): the MSS, window scaling (section 5), SACK permitted (section 4) and timestamps. On every one of this page's connections to Cloudflare the kernel reported all four plus ECN (section 6) as agreed (TCP_CONNECTION_INFO options = 15). A middlebox that strips an option from the SYN removes that feature for the life of the connection, silently.

macOS. This Mac uses an MSL of 15 s, so TIME_WAIT is 30 s (measured net.inet.tcp.msl: 15000); its netstat listed no TIME_WAIT entry after twenty closed loopback connections, so the state could not be seen here and the numbers above are Linux's.

Kernel knobs, a last resort. tcp_tw_reuse lets outgoing connections reuse a TIME_WAIT port when timestamps prove it safe (default 2, loopback only, ip-sysctl); tcp_tw_recycle, still recommended by old blog posts, was removed in Linux 4.12 because it broke clients behind NAT (commit 4396e46187ca).

4. Loss: acknowledgements, timers and head-of-line blocking

The receiver keeps saying "I have every byte up to n" (a cumulative ACK); a segment sent but not yet acknowledged is in flight. If segment 5 of 10 is lost, 6 to 10 still arrive, but the receiver can only repeat "up to the end of 4": these repeats are duplicate ACKs, and the bytes of 6 to 10 wait in the receive buffer, invisible to the application, until 5 is repaired. That wait is head-of-line blocking, and it is why HTTP/2's many streams on one TCP connection all stall on one loss while HTTP/3's do not (the root's On the wire tab measured one lost packet delaying all three HTTP/2 streams and only one HTTP/3 stream).

A sender decides a segment is lost in one of two ways:

  • Retransmission timeout (RTO). It keeps a smoothed RTT and a variance and sets RTO = smoothed RTT + 4 × variance (RFC 6298); nothing acknowledged before the timer fires means resend, and double the timer for the next try. RFC 6298 says the RTO should never go below 1 second; Linux uses a 200 ms floor (TCP_RTO_MIN (HZ / 5)), a 1 s initial value and a 120 s ceiling (tcp.h). A timeout is expensive: at least 200 ms idle, and the congestion window collapses to one segment (section 6).
  • Fast retransmit. Three duplicate ACKs mean later segments are arriving, so the missing one is probably lost: resend at once, one round trip after the loss instead of a timer later (RFC 5681 s3.2). SACK (selective acknowledgement, RFC 2018) also reports which later blocks arrived, so several holes are repaired in one round trip.
  1. Token 1 arrives and is read at once. Written at 273.8 ms (times from the client's SYN, on a 100 ms round trip), it lands 50 ms later, at 323.8 ms, and goes straight to the program.
  2. Token 2 is lost. It leaves at 325.1 ms and never arrives. Nothing tells the server yet.
  3. Tokens 3 to 5 arrive and wait. They land between 426.5 and 530.1 ms, but bytes are handed over only in order, so they sit in the receive buffer behind the hole: head-of-line blocking. Each triggers a duplicate ACK 503, "I still have everything up to byte 503".
  4. Timer only: the duplicates are ignored. The retransmission timer, 300 ms here (the round trip plus Linux's 200 ms floor) and restarted by the last new ACK at 413.8 ms, fires at 713.8 ms, and token 2 is sent again.
  5. The hole fills: four tokens in one read. The copy lands at 763.8 ms and the receiver hands tokens 2 to 5 to the program together.
  6. The cost. Token 2 reaches the program 388.6 ms later than its one-way trip, and token 5, which arrived intact, 234.7 ms late. Switch to fast retransmit to see 134.7 ms of that disappear.

illustrative model with recorded inputs: the root's streaming request replayed by the model of the timeline below (delayed ACKs on, TCP_NODELAY on).

The timeline: the same request, every segment

A token stream breaks fast retransmit. It needs later segments to generate duplicate ACKs, and a stream sends one small segment every 50 ms or so; if the last segment is lost there is nothing behind it. Linux's answer is RACK-TLP (RFC 8985): call a segment lost when one sent after it has been acknowledged and a reordering window has passed, and when the tail goes quiet, send a tail loss probe after about two round trips to provoke an ACK that reveals the hole.

The root's streaming request (277 bytes up; a 244-byte response head, then seven Server-Sent Events written at the times the root recorded: 2.4, 123.8, 175.1, 226.5, 278.0, 329.1 and 330.1 ms after the request arrived), replayed over one TCP connection. Time runs down, to scale. Predict first: with "Token 2 lost", which tokens does the client application see late, and why do tokens 3 to 5 wait too? Then flip Recovery.

The model's rules (what is simplified)

One-way delay is half the round trip; segments up to 1,448 bytes; the receiver ACKs every second segment or after 40 ms (Linux's minimum delayed ACK) and at once for out-of-order data (RFC 5681 s4.2); the sender retransmits on three duplicate ACKs (s3.2), after a tail-loss probe at two round trips (RFC 8985 s7), or when its timer fires at RTT + 200 ms, doubling after each expiry; Nagle holds a small write while data is unacknowledged (RFC 9293 s3.7.4). No TLS (as on the root's plain port), no congestion window limit (seven small segments never reach the initial window of 10), no queueing. Real stacks differ in detail (RACK time-based detection, SACK); the order of events and the size of each wait are the point.

The same request, the same lost token: the timer costs hundreds of milliseconds, fast retransmit one round trip

Scenario
Recovery
Small writes (section 7)
Client ACKs

illustrative model with recorded inputs "Last token lost" has no later segments and no duplicate ACKs, so only the probe or the timer can notice.

Loss on a real path, and the counters that show it (depth)

In two of this page's twelve downloads the receiver held out-of-order bytes for repair (36,608 and 254,880 bytes, tcpi_rxoutoforderbytes, measured); the other ten saw none. The application never noticed: TCP repaired the holes and delivered in order, and the cost (about a round trip, a smaller window) is invisible unless you read the per-connection counters.

Retransmissions inside a data centre should be near zero; growth there is a real fabric or NIC problem. Linux: nstat -az TcpRetransSegs before and after a test, and ss -ti per connection (retrans: current/total, lost:, rto:). macOS: netstat -s -p tcp | grep -i retrans. A connection whose RTO has backed off to tens of seconds looks hung; it is waiting for its timer.

5. Windows: one connection carries at most one window per round trip

Every ACK carries the receiver's receive window, the free space left in its buffer, and the sender never has more unacknowledged bytes in flight than that (flow control). A second cap, the congestion window (section 6), protects the network; the sender may have min(receive window, congestion window) in flight. It sends one window, then waits a round trip for the acknowledgements, so at most one window arrives per round trip, however fast the link:

throughput ≤ window / RTT    and to fill a link: window ≥ bandwidth × RTT (the bandwidth-delay product, BDP)
window
bytes allowed in flight without acknowledgement
RTT
round-trip time; under load it includes queueing (section 6)
BDP
10 Gbit/s × 100 ms = 125 MB; 25 Gbit/s × 1 ms = 3.1 MB; 100 Gbit/s × 50 µs = 625 KB (derived)
  1. The path is a pipe. Its length is the round trip (about 20 ms smoothed in these runs) and its width the bottleneck rate (about 46 Mbit/s, the fastest any run went), so it holds 46 Mbit/s × 20 ms ≈ 115 KB in flight: the bandwidth-delay product (derived).
  2. A 16 KB buffer fills a quarter of it. The kernel advertised 28,728 to 29,776 bytes; the sender puts that much in flight, then waits for the ACKs while the link idles for most of each round trip. Measured 11.3 to 13.2 Mbit/s; window / RTT predicts 11.3 to 12.8.
  3. 64 KB fills about half. A 65,536-byte window: 25.4 to 27.3 Mbit/s measured, 26.2 to 27.6 predicted.
  4. 256 KB is more than the pipe holds. The window exceeds the BDP, so the link binds at 45.4 to 46.0 Mbit/s. The excess cannot go faster; it waits in the bottleneck's queue, and by the end of these runs the round trip had grown to 37 to 44 ms: about 126 KB queued (rate × the extra round trip, derived).
  5. Autotuned: the kernel grows the window, the queue grows too. The window reached 0.9 to 1.4 MB, far beyond the pipe, at the same 45.9 Mbit/s, and the round trip at the end was 35 to 49 ms, about 136 KB queued: the bufferbloat of section 6.

measured: the twelve downloads below, three per buffer; the pipe and the train of bytes in flight are drawn to the runs' windows and goodputs.

The header's window field is 16 bits, so without help the largest window is 65,535 bytes: over a 100 ms path that caps one connection at 65,535 × 8 / 0.1 = 5.2 Mbit/s whatever the link (derived). The window-scale option (RFC 7323 s2) multiplies the field by 2shift, shift at most 14 (windows up to 1 GiB), agreed once in the SYN. A middlebox that strips it, or a socket whose buffer was small when it connected, is stuck with a small window for life.

The buffer you set is the speed you get: measured goodput follows window / RTT until the link binds

measured Twelve downloads from Cloudflare's speed-test endpoint, one TCP connection each, the receive buffer fixed with SO_RCVBUF before connect() or left to the kernel, goodput over the second half of each transfer. The prediction is the window the kernel reported over the measured smoothed RTT; the link tops out near 46 Mbit/s.

Defaults reproduce the window-over-RTT rule independently: for the two window-limited buffers goodput is within about 10 percent of window / RTT (the RTT is reported in whole milliseconds, so the prediction is only that precise); at 256 KB and with autotuning the prediction exceeds the link, and the link wins. The kernel advertised 28,728 to 29,776 bytes for a 16 KB request: macOS sizes the buffer above what you ask, so read the window the kernel reports (tcpi_rcv_wnd), not the number you passed. Raw runs: src/meas/out/tcp_path.json.

All twelve runs (table)

Autotuning. Modern kernels grow the receive buffer as the connection proves it needs one. In the autotuned runs the advertised window grew from 128 KB to about 0.9 to 1.4 MB within a few hundred milliseconds (measured, first run below), with a window-scale shift of 6 against 3 when the buffer was fixed small: the kernel picks the shift at connect() from the buffer size at that moment.

The trap: setting a buffer can make you slower
Linux documents that setsockopt(SO_RCVBUF) disables receive autotuning for that socket (tcp_rmem in ip-sysctl). A client "tuned" with a 256 KB buffer is capped at 256 KB / RTT: 21 Mbit/s on a 100 ms cross-region path (derived), far below an untuned client whose window grows to tcp_rmem's maximum (default between 128 KB and 32 MB depending on memory). Two separate knobs: net.ipv4.tcp_rmem's third value caps autotuning; net.core.rmem_max caps only explicit setsockopt calls, and its default rose from 212,992 bytes to 4 MB in Linux 6.18 (commit a6d4f25888b8), so guides that quote "208 KB" describe older kernels. For a 10 Gbit/s, 100 ms path the third value of tcp_rmem and tcp_wmem must be at least the 125 MB BDP.

The autotuned window grew from 128 KB to about 0.9 MB within half a second

How a window-limited transfer shows up (commands)

A transfer far below link speed with no retransmissions, and a throughput that changes with distance rather than load. ss -ti on Linux shows rcv_space, snd_wnd and cwnd; iperf3 -c host -P 1 against -P 8 demonstrates the per-connection cap to anyone who doubts it. The throughput calculator in section 13 works out which limit binds for a path you describe.

After each loss CUBIC is back near the old window in about 9 s (K, derived); Reno needs tens of seconds

illustrative, computed from the RFC formulas One flow, one step per 100 ms round trip, on a path that holds 1,000 segments in flight (about 117 Mbit/s with 1,460-byte segments): a window above that overflows the bottleneck buffer and loses a packet, and both flows also lose one packet the queue did not cause, at 25 s. Reno follows RFC 5681; CUBIC follows RFC 9438 s4 (C = 0.4, β = 0.7, with its Reno-friendly floor; fast convergence not modelled). Both start in slow start; queueing delay and timeouts are left out.

6. Congestion control: sharing a link nobody owns

The receive window protects the receiver; nothing in it protects the routers between. If every sender sent as fast as its window allowed, router queues would overflow and throughput would collapse, as the internet did in October 1986 (Jacobson and Karels, 1988). So each sender also keeps a congestion window (cwnd), its own estimate of what the path can carry, and probes for more while watching for overload.

Slow start. A new connection starts at 10 segments (RFC 6928; TCP_INIT_CWND 10 in Linux) and adds one per ACK, doubling every round trip, until a loss or the slow-start threshold. Reaching a 125 MB window from 14.6 KB takes about log2(125 MB / 14.6 KB) ≈ 13 round trips, 1.3 s on a 100 ms path (derived); this page's home line (about 115 KB, Fig. 4) fills in about 3. A 2 KB API response finishes inside slow start, so for it latency, not bandwidth, is everything. Linux also returns to slow start after a connection has been idle for one RTO (tcp_slow_start_after_idle, default on), so a burst after a pause starts small again.

Reno: after slow start, add one segment per round trip and halve on loss, additive increase, multiplicative decrease (RFC 5681). Fair and stable, and hopeless on long fat paths: after one loss at a 10,000-segment window, one segment per 100 ms round trip needs 5,000 round trips, over 8 minutes, to get back (derived). CUBIC, the default in the Linux, Windows and Apple stacks (RFC 9438 s1; this Mac reports net.inet.tcp.use_newreno: 0 and 209 sockets on CUBIC), grows as a cubic in time since the last loss, W(t) = C (t − K)3 + Wmax with C = 0.4, cuts to 0.7 instead of 0.5, and K is the time to climb back to the window where the loss happened: back fast, careful past the old level, then accelerating. Because it runs on time, not round trips, long-RTT flows recover as fast as short ones.

  1. Slow start overshoots. From 10 segments the window doubles every round trip and passes the path's 1,000 segments within a second; at 1,280 the queue overflows (0.7 s) and Reno halves to 640.
  2. One segment per round trip. Additive increase: from 640 the window has crept only to 732 by 10 s.
  3. Still climbing. At 24 s it is at 872, still below the capacity it lost at the start.
  4. A loss the queue did not cause. At 25 s one packet is lost anyway, and 882 halves to 441.
  5. After 60 s. The window is back to 790 and the path was 67% used on average: Reno spends tens of seconds climbing back after every loss.

The cost of filling the pipe: queues. Reno and CUBIC learn they went too fast only when a queue overflows, so they keep the bottleneck's buffer full. measured on this page's home line, ping every 100 ms with one 25 MB download in the middle: the download ran at 44.1 Mbit/s and the round trip went from a 14.4 ms median at idle to 37.0 ms while it ran: about 23 ms of queue, roughly 125 KB waiting at the bottleneck (44.1 Mbit/s × 22.6 ms, derived). Section 5's runs show it too: the window-limited downloads ended with a current RTT of 17 to 22 ms, the ones that filled the link 35 to 49 ms. Interactive traffic on that link (a video call, the next streamed token) waits in the same queue: bufferbloat.

During one download the median round trip on the line more than doubles

BBR (Bottleneck Bandwidth and Round-trip propagation time, from Google) models the path instead of reacting to loss: it estimates bottleneck bandwidth and minimum RTT and paces at that rate, keeping the queue near empty. It shines on long paths with random, non-congestive loss, where CUBIC would back off for nothing, and is in Linux since 4.9 (commit 0f8782ea1497). Its current version is still an IETF draft, draft-ietf-ccwg-bbr-06 (6 July 2026), not an RFC; check what a kernel ships with sysctl net.ipv4.tcp_available_congestion_control. Only the sender chooses: on a download, the server's algorithm decides, not yours.

Signals other than loss, and when not to touch it (depth)

ECN (RFC 3168) lets a router mark a packet "congestion experienced" instead of dropping it, and the receiver echoes the mark; this Mac negotiated it on every connection recorded here. L4S (RFC 9330, 2023) builds on it for very low queueing delay; ISPs deploy it, you do not tune it on a cluster.

Inside one data centre on a clean network the default is almost always right; the wins from BBR are on long, lossy paths (cross-region replication, uploads from a home line). One BBR flow can take more than its share from CUBIC flows on a shallow-buffer link, so test before switching a fleet.

7. Small writes: Nagle, delayed ACKs and streamed tokens

Nagle's algorithm (RFC 896, January 1984; RFC 9293 s3.7.4) was the fix for terminals sending one 41-byte packet per keystroke (40 bytes of headers, 1 of data): while any sent data is unacknowledged, hold new small writes and send them together when the ACK arrives or a full segment accumulates. On the other side, a receiver may wait before acknowledging, hoping to piggyback the ACK on a reply: a delayed ACK, under 0.5 s, with an ACK for at least every second full-sized segment (RFC 1122 s4.2.3.2). Linux delays between 40 ms and 200 ms (TCP_DELACK_MIN (HZ/25), TCP_DELACK_MAX (HZ/5) in tcp.h).

Together they stall. A client writes a request in two pieces (headers, then body): the first goes out; Nagle holds the second until the first is acknowledged; the server, holding half a request, has nothing to reply with, so its delayed ACK waits 40 ms or more. Every request pays it. A token stream is bitten the same way: token 2 is written while token 1 is unacknowledged, so Nagle holds it until token 1's ACK returns a full round trip later. On a 100 ms path, tokens that left the model 50 ms apart arrive in clumps, one clump per round trip.

See it in the timeline of section 4
Set Scenario to Clean and Small writes to "Nagle on" at 100 ms: tokens leave in pairs, one pair per round trip. Then set the round trip to 10 ms: Nagle barely matters, which is why it hides on fast networks and in tests.

The fix is one socket option. TCP_NODELAY turns Nagle off so every write goes out at once. Latency-sensitive stacks set it by default: gRPC's C core calls grpc_set_socket_low_latency(fd, 1) on its client and server sockets (tcp_client_posix.cc), and Go's TCP connections start with no delay (SetNoDelay: "The default is true"). TCP_CORK (Linux) is the deliberate opposite: assemble a response from several writes and release it as full segments.

Measured: the asyncio server side was left with Nagle on

Python's asyncio sets TCP_NODELAY on every TCP transport, but only when the socket reports its protocol as TCP (sock.proto == IPPROTO_TCP in asyncio/base_events.py, read in the 3.13.5 source). On this Mac a socket returned by accept() reports protocol 0, so the server side of an asyncio connection kept Nagle on while the client side had it off. Whether your server framework sets the option is worth one getsockopt call. The root's Failure lab could not reproduce the stall on this Mac's loopback (case "Nagle plus delayed ACK (not reproduced on macOS loopback)"): there the ACK returns in microseconds, so nothing waits. The stall needs a real round trip.

How it shows up (commands)

Latency per request of almost exactly 40 ms (or 200 ms) more than the work takes, independent of payload size; streamed tokens arriving in bursts rather than evenly. Check getsockopt(IPPROTO_TCP, TCP_NODELAY) on both ends, or a packet capture (tcpdump, needs root) showing small segments waiting for ACKs. Fix: set TCP_NODELAY on both ends, and write each logical message in one call.

8. The server side: accept queues, shared ports, file descriptors

The kernel completes the handshake on its own; accept() only hands your program a connection that is already established. Finished connections wait in an accept queue as long as the backlog passed to listen(), capped by somaxconn: 4,096 on Linux since 5.4 and 128 before (ip-sysctl; many tuning guides predate the change), and 128 on this Mac (measured kern.ipc.somaxconn). A server that accepts more slowly than clients arrive (a single process busy loading a model, a rendezvous rank before it calls accept) fills it.

When it is full, Linux drops new SYNs (tcp_conn_request in tcp_input.c counts a ListenOverflow and drops), so the client resends its SYN after its 1 s initial timeout, then 2 s later: connects that take 1 s or 3 s instead of a millisecond. A handshake that completes while the queue is full has its final ACK ignored, unless tcp_abort_on_overflow is on, which sends the client a reset instead (tcp_minisocks.c; off by default).

  1. listen(2). The server's kernel will complete handshakes by itself and keep at most 2 finished connections waiting for accept(): this experiment's backlog, far below the caps above.
  2. Clients 0 and 1 connect. Their handshakes complete in 0.3 to 0.4 ms and the connections wait in the queue; the server is busy and has not called accept().
  3. Clients 2 to 7 connect too. On this Mac five more connect() calls return success in 0.3 to 0.4 ms and client 4's is reset at once: seven of eight connects succeeded, though only two connections fit the queue.
  4. Every connected client sends its request. Clients 0 and 1 send theirs; the other five get BrokenPipeError: at the server, their connection no longer exists.
  5. The server finally accepts. It gets exactly two connections, reads "hello 0" and "hello 1" and answers both; the five others read "Connection reset by peer".
  6. On Linux a full queue drops the SYN instead. The client resends after 1 s, then 2 s more: connects of 1 s or 3 s (the kernel source above, not measured here).
  7. Many workers, one port. With SO_REUSEPORT each worker process binds the same port with its own queue and the kernel spreads new connections across them, so they accept in parallel (illustrative: four workers).

Seven of eight connects succeeded; only two clients were ever served

measured on this Mac with listen(2) and a server that does not call accept() until all eight clients have tried.

The others learned they had been dropped only when they wrote (broken pipe) or read (reset). A successful connect is not a server that will answer: a client needs a read timeout as well as a connect timeout, and a health check should send a request, not just open a socket.

Many workers, one port. SO_REUSEPORT lets several sockets, typically one per worker process, bind the same address and port, and the kernel spreads new connections across them, so N workers accept in parallel instead of fighting over one queue (man 7 socket). SO_REUSEADDR is different and older: it lets a restarted server bind its port while old connections on it are still in TIME_WAIT, which is why almost every server sets it.

Every connection is a file descriptor, and processes have a limit (ulimit -n). A server with thousands of streaming clients, or a dataloader whose workers each hold connections, hits it with EMFILE ("Too many open files"); compare ls /proc/PID/fd | wc -l with the limit.

Seeing the queue on Linux, and file limits under Slurm (a correction) (depth)

ss -lnt: for a listening socket, Recv-Q is the current accept-queue length and Send-Q its limit (idiag_rqueue = sk_ack_backlog, idiag_wqueue = sk_max_ack_backlog in tcp_diag.c). nstat -az TcpExtListenOverflows TcpExtListenDrops counts the drops. Fix: accept faster (more workers, an event loop), raise the backlog in the code and somaxconn, and have clients retry with jitter.

On Slurm clusters a job inherits the soft limits of the shell it was submitted from unless the administrator configured otherwise (PropagateResourceLimits, whose default is to propagate all limits, slurm.conf); check inside the job with srun bash -c 'ulimit -n' rather than trusting the login node.

Correction to the old page
The old page said that on Slurm "limits are inherited from slurmd's environment rather than your login shell, so ulimit -n in your .bashrc will not help a job". The current slurm.conf documentation says the opposite by default: slurmd reads the soft limits from the user's environment on the submit node and applies them to the job, unless PropagateResourceLimits or PropagateResourceLimitsExcept is configured. What is true: a cluster can be configured not to propagate, and a job cannot raise a limit above what the node allows.

The mapping is forgotten at 350 s; a probe every 300 s keeps it

illustrative, with AWS's documented 350 s idle timeout A pod in a private subnet holds one connection to an external API through a NAT gateway; it streams one request, then the connection sits idle in its pool for 6 minutes before being reused. Predict the error the reused connection gets.

9. NAT, idle timeouts and dead peers

A machine with a private address (section 1) reaches the internet through network address translation: a NAT device (a home router, a cloud NAT gateway, a Kubernetes node doing SNAT for its pods) rewrites each outgoing packet's source address and port to its own public address and a port it allocates, and remembers the mapping so it can rewrite the replies back. To the NAT, that table entry is the connection. Two limits follow: the table has a size, and entries that look idle are thrown away.

Idle timeouts are shorter than you think. The IETF asks that an established TCP mapping survive at least 2 hours 4 minutes idle (RFC 5382 REQ-5) and a UDP mapping at least 2 minutes (RFC 4787 REQ-5), but devices choose their own: an AWS NAT gateway times out a connection idle for 350 seconds and answers later packets with a reset, not a FIN (AWS NAT troubleshooting). Load balancers have their own idle timers. Neither end is told: the next write fails with "connection reset by peer", or, if the middlebox drops silently, hangs until a retransmission timer gives up.

  1. The pod opens a connection. The SYN leaves the pod from 10.0.1.23:41000. The NAT gateway rewrites the source to its public address and a free port, 198.51.100.7:1024, and writes the mapping into its table.
  2. The request streams; the mapping is in use. Every packet in either direction refreshes the entry. The response streams back through the same mapping, rewritten to 10.0.1.23:41000.
  3. The client returns the connection to its pool. Nothing is sent now. TCP has no idea anything is wrong: both ends still hold an ESTABLISHED socket.
  4. 300 s of silence. Default keepalive would wait 7,200 s; this socket has none. The mapping ages.
  5. 350 s idle: the gateway deletes the mapping. The NAT gateway times out the connection after 350 s of idleness. It tells neither end.
  6. The pooled connection is reused: reset. The request reaches the gateway, which has no mapping for it, and answers with a reset (AWS documents RST, not FIN). The client sees "Connection reset by peer" (ECONNRESET) and must open a new connection: a new handshake, a new TLS handshake, and a retry it hopefully knows is safe.
  7. Before. This is the shape of "works in testing, fails after lunch": only connections idle longer than a middlebox timer break, and the error blames the peer.

TCP keepalive is not a heartbeat by default. With SO_KEEPALIVE on, Linux waits 7,200 s idle, then probes 9 times 75 s apart: 7,200 + 9 × 75 = 7,875 s, 2 hours 11 minutes, before it declares a silent peer dead (TCP_KEEPALIVE_TIME (120*60*HZ), TCP_KEEPALIVE_PROBES 9, TCP_KEEPALIVE_INTVL (75*HZ) in tcp.h). This Mac uses 7,200 s, 75 s and 8 probes (measured sysctl). Both are far longer than a 350 s NAT timeout, so set the per-socket options (TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT on Linux; TCP_KEEPALIVE on macOS) below the shortest idle timer on the path, as AWS's own fix says, or have the pool discard connections idle longer than that.

Keepalive cannot see a wedged peer. A process that is alive but stuck (a rank deadlocked in a collective, a server in a long garbage collection) still has a kernel that answers probes. For data you have sent, TCP_USER_TIMEOUT bounds how long it may stay unacknowledged before the connection is dropped (Linux 2.6.37 and later, man 7 tcp; standardised as an option in RFC 5482). For everything else you need an application heartbeat and a deadline: NCCL's watchdog timeout in PyTorch, gRPC deadlines, an SSE stream's ping events.

NAT tables fill up, the symptoms of a middlebox timer, recorded cases (depth)

The root's Failure lab cases "Reused keep-alive connection closed by the server" and "Read timeout: connected, then nothing" show both shapes with real client errors; the SSH page (its section 9) records ServerAliveInterval detecting a dead path in seconds where TCP keepalive would take two hours.

Every connection through a NAT uses one of its source ports. An AWS NAT gateway supports up to 55,000 simultaneous connections per public IPv4 address to each unique destination (destination address, port and protocol), 5 Gbit/s scaling to 100 Gbit/s, and 1 to 10 million packets per second; beyond the connection limit its ErrorPortAllocation metric counts the connections it could not open (NAT gateway basics, CloudWatch metrics). A fleet of dataloader workers opening fresh connections to one storage endpoint can reach it. Fixes in order: reuse connections; add addresses to the gateway; and for S3 or DynamoDB, take NAT out of the path with a gateway VPC endpoint, which has no additional charge and needs no NAT device (gateway endpoints).

Failures only after idle periods, at a suspiciously round interval (350 s, 600 s, 3,600 s): a middlebox idle timer; compare the failure timestamps with each connection's last use. New connections failing while old ones work: a full NAT table (the gateway's port-allocation metric; on a Linux NAT, conntrack -S). ss -to (Linux) shows each socket's keepalive timer.

10. MTU: the largest packet, and the hang it causes

Every link has a maximum transmission unit (MTU), the largest IP packet it carries: 1,500 bytes on standard Ethernet, less on links that wrap packets in extra headers. A bigger packet must be fragmented or dropped, and fragmentation is fragile (lose one fragment, lose the packet), so TCP avoids it: each side announces an MSS in its SYN, the MTU minus IP and TCP headers (1,500 − 20 − 20 = 1,460 for IPv4; 1,440 for IPv6), and the timestamp option then takes 12 bytes of every segment (the hero's 1,448).

Path MTU discovery. A link further on may be smaller than yours. So TCP sends with the Don't Fragment bit set, and a router that cannot forward a packet drops it and returns ICMP "fragmentation needed" with the next link's MTU (IPv4, RFC 1191) or "packet too big" (IPv6, RFC 8201); the sender shrinks its packets for that destination.

One byte over 1,492 and the home router sends back "frag needed"

measured from this laptop (interface MTU 1,500) with don't-fragment pings to Cloudflare's resolver: the router answered the oversized probes with exactly that message, naming an MTU of 1,492, and a binary search found the largest payload that gets through, 1,464 bytes (+ 28 bytes of IP and ICMP headers = 1,492).


The black hole

Path MTU discovery depends on that ICMP message coming back. A firewall or security group that drops all ICMP breaks it, with a signature worth memorising: the handshake and small requests work, then the first full-size packet vanishes and the transfer hangs. A TLS handshake whose certificate chain needs a full-size packet, a large POST, a model download or an allreduce over a VPN all stall while curl to a health endpoint passes. Fixes: allow ICMP "fragmentation needed" / "packet too big" through; clamp the MSS on the tunnel or router; or let TCP find the size by probing (packetization-layer PMTUD, RFC 4821; Linux net.ipv4.tcp_mtu_probing=1 turns it on when a black hole is detected, 2 always, default 0, ip-sysctl). QUIC and other datagram protocols probe the same way (RFC 8899).

Jumbo frames and the mixed-MTU trap

Inside an AWS VPC every current-generation instance supports 9,001-byte jumbo frames, about six times fewer packets per byte (derived: 8,949 / 1,448 payload bytes per segment with timestamps). Traffic through an internet gateway, over a VPN, or between regions (unless through a transit gateway) is limited to 1,500, and inter-region VPC peering to 8,500 (EC2 network MTU); AWS recommends jumbo frames within one cluster placement group. Two failures follow: traffic leaving the VPC at 9,001 depends entirely on path MTU discovery working; and nodes of one job with different MTUs (one image sets 9,001, another 1,500) pass every small message and hang on the first large one, such as a training job's first large allreduce. Check every node: ip link show (the mtu field), then ping -M do -s 8973 peer (Linux; 8,973 + 28 = 9,001) between each pair.

Correction to the old page
The old page said NAT gateways cap at 8,500 bytes. The current EC2 MTU documentation (fetched 5 October 2026) lists 8,500 only for inter-region VPC peering, and 1,500 for internet gateways, VPN and inter-region traffic; it gives no NAT gateway figure, so this page does not repeat one.
Why 1,492, commands, and why IPv6 was not probed (depth)

1,492 is the signature of PPPoE, which carries IP over a DSL or fibre line inside an 8-byte header (RFC 2516: "the PPP MTU MUST NOT be greater than 1492"). The TCP connections on this path used segments of 1,388 bytes (tcpi_maxseg), below the 1,492 − 40 − 12 = 1,440 this link allows (derived), so the smaller limit came from the server's side, which cannot be seen without a packet capture.

macOS: ping -D -s 1472 host (1,472 + 28 = 1,500); Linux: ping -M do -s 1472 host, and tracepath host, which reports the path MTU hop by hop without root. A reply of "frag needed and DF set (MTU n)" tells you the limit; silence at one size and success just below it, with no ICMP message, is a black hole. IPv6 could not be probed the same way here: ping6 -D needs root on macOS ("IPV6_DONTFRAG: Operation not permitted").

11. UDP: a thin wrapper, and everything else is your problem

UDP adds an 8-byte header to IP: source port, destination port, length, checksum (RFC 768). No connection, handshake, acknowledgement, retransmission, ordering, flow or congestion control; what it keeps is message boundaries: each sendto is one datagram, delivered whole or not at all (section 2's recording shows three sends arriving as three reads). Use it when a late packet is worthless (voice, video, game state), when a question and its answer each fit in one packet (DNS), or to build your own transport in user space (QUIC). The price includes congestion control: an application that blasts UDP at a fixed rate harms everyone on the link, which is why the UDP usage guidelines ask UDP applications to control their rate.

A QUIC implementation treats those drops as network loss and slows down, so an undersized UDP buffer silently caps HTTP/3 throughput. quic-go's documentation recommends raising the Linux limits to about 7.5 MB (net.core.rmem_max and wmem_max = 7,500,000, quic-go wiki); Linux's default limit was 212,992 bytes until 6.18 raised it to 4 MB (section 5). HTTP/3 is not niche: W3Techs counted it on 40.8 percent of websites on 5 October 2026 (W3Techs).

No window to push back: a busy reader with a 64 KB buffer kept 53 of 5,000 datagrams

measured on loopback: 5,000 datagrams of 1,200 bytes sent in one burst at a socket that reads only after the burst. TCP's buffer grows and its window slows the sender; a UDP socket has a fixed buffer, and datagrams that arrive while it is full are discarded with only a counter to record it.

Datagram sizes that matter, and the drop counters (reference)
Size (UDP payload)Where it comes from
1,472 / 1,452largest payload in one 1,500-byte packet over IPv4 / IPv6 (1,500 − 20 or 40 − 8, derived); larger datagrams are fragmented, and losing one fragment loses the datagram
1,232the EDNS buffer size DNS Flag Day 2020 recommends as the default: IPv6's 1,280 minimum MTU minus 48 bytes of IPv6 and UDP headers (dnsflagday.net/2020); larger DNS answers fall back to TCP
1,200the smallest maximum datagram size QUIC requires a path to carry, and the size a client pads its first datagram to (RFC 9000 s14; measured in section 12)
9,216the largest datagram this Mac's kernel accepts at all (measured: 9,216 bytes sent, 9,217 refused with "Message too long", net.inet.udp.maxdgram); the protocol itself allows up to 65,507 over IPv4 (65,535 − 20 − 8, derived)

Linux: nstat -az | grep -i udp, where a growing UdpRcvbufErrors means the buffer overflowed; ss -uam shows each socket's buffer use. macOS: netstat -s -p udp, "dropped due to full socket buffers" (the counter this page's measurement read before and after). Where you meet UDP in ML: DNS on port 53 (packets, truncation and TCP fallback recorded on the DNS page), HTTP/3 on 443, NTP for clocks (TLS and token validity depend on them), and RoCEv2 between GPUs (section 14).

The client's port changes mid-connection: TCP's 5-tuple matches no socket, QUIC's connection ID still matches

The QUIC run is real: aioquic 1.3.0 on loopback, a client and a small echo server, every UDP datagram logged with its size and source port, and both endpoints' qlog (QUIC's standard event log) recording the packet types and frames inside (src/meas/quic_migrate.py). Midway the client moves to a new UDP socket, which is what a NAT rebinding or a switch from Wi-Fi to mobile looks like to the server. The TCP side is drawn from the specification, not recorded.

12. QUIC: TCP's job, rebuilt on UDP

TCP plus TLS has three costs that could not be fixed inside TCP: a round trip for TCP and another for TLS 1.3 before the request leaves (section 3); one ordered byte stream under all of HTTP/2's streams, so one loss stalls them all (section 4); and ossification: firewalls, NATs and load balancers parse TCP's headers and drop what they do not recognise, and TCP lives in kernels that update slowly, so new TCP features take a decade to deploy, if ever. QUIC (RFC 9000, May 2021, started at Google) moves the transport into a library on UDP and encrypts almost everything so middleboxes cannot ossify it again.

  • One handshake for transport and encryption. TLS 1.3 runs inside QUIC's packets (RFC 9001), so the connection is ready after one round trip. A returning client can send its request in the first flight (0-RTT), but that data can be replayed by an attacker who records it (RFC 9001 s9.2): use it only for requests safe to repeat.
  • Streams, each with its own order and flow control. A lost packet holds up only the streams whose data it carried.
  • Packet numbers are never reused. A retransmission goes in a new packet with a new number, so an ACK is never ambiguous about which copy arrived and RTT samples are clean (RFC 9002 s4.2). ACK frames list ranges, like SACK without a size limit. A packet is lost when three later packets are acknowledged or after 9/8 of an RTT (RFC 9002 s6.1); the congestion controller the RFC describes is close to TCP's NewReno (RFC 9002 s7), and implementations may plug in others.
  • Connections are named by connection IDs, not addresses, so they survive a change of address or port (connection migration, RFC 9000 s9); the peer checks the new path with PATH_CHALLENGE and PATH_RESPONSE before trusting it.
  • No amplification. Until it has validated the client's address, a server may send at most three times the bytes it received (RFC 9000 s8.1), one reason the client pads its first datagram to 1,200 bytes: it buys the server room for its certificate.
  1. The client's first datagram. An Initial packet carrying the TLS ClientHello, padded to 1,200 bytes, as RFC 9000 requires of a client's first flight.
  2. The server's flight. An Initial (ServerHello) and a Handshake packet (certificate and Finished) coalesced in one 1,200-byte datagram: within the three-times limit, since it has received 1,200 bytes.
  3. Ready after one round trip. The client finishes the handshake and already sends 1-RTT packets, then the first request ("before") on stream 0 (37 bytes); the server confirms with HANDSHAKE_DONE, hands out spare connection IDs (224 bytes) and echoes the request.
  4. The client moves to a new UDP socket. Source port 63726 becomes 63057, which is what a NAT rebinding or a Wi-Fi to mobile switch looks like to the server. The second request ("after") goes out from the new port on the same connection, with no handshake, under a fresh connection ID the server issued earlier, so an observer cannot link the two paths.
  5. The server checks the new path. Its connection ID arrives from a new port; the server sends the echo there and a PATH_CHALLENGE (8 random bytes) with it, in an 80-byte datagram. The client's PATH_RESPONSE echoes the challenge: the path is validated, and the connection never stopped.
  6. The client closes. A CONNECTION_CLOSE in a 30-byte datagram: 12 datagrams in all, both replies received on one connection.

Costs. QUIC runs in user space, encrypting and acknowledging every packet itself, so it spends more CPU per byte than kernel TCP with its offloads. Some networks block or throttle UDP 443, so every client keeps a TCP fallback: it learns a server speaks HTTP/3 from an alt-svc header or a DNS HTTPS record, then races or falls back. Inside a data centre on a clean network, kernel TCP is usually cheaper and simpler; between your own services gRPC and most inference servers still use HTTP/2 over TCP.

Visibility, versions, datagrams, debugging QUIC (depth)

QUIC hides its headers from network operators who used to read TCP's to debug (RFC 9312 discusses what remains visible). QUIC v2 (RFC 9369, 2023) changes nothing functional; it exists so that middleboxes do not hard-code version 1. RFC 9221 adds unreliable datagrams inside a QUIC connection, for media and tunnels. Packet captures show only encrypted payloads; use the endpoints' qlog files (aioquic, quic-go, Chrome's chrome://net-export) or SSLKEYLOGFILE to decrypt a capture in Wireshark. "HTTP/3 fast at home, slow or falling back in the office": UDP 443 blocked. This laptop's curl 8.7.1 has no HTTP/3 support at all, which the root page also notes; the root's On the wire tab measured cold, resumed and 0-RTT connections.

13. Moving big things: checkpoints, datasets, weights

A 70-billion-parameter model in bf16 (2 bytes per parameter) is 140 GB of weights. A full training checkpoint with Adam in mixed precision usually also holds an fp32 master copy and two fp32 moments, 4 + 4 + 4 more bytes per parameter: 14 bytes per parameter, 980 GB (derived; layouts vary by framework). Over one connection capped at 5 Gbit/s that is 140 × 8 / 5 = 224 s for the weights and 980 × 8 / 5 = 1,568 s, 26 minutes, for the full state (derived), per checkpoint, while the GPUs may wait. One connection has four separate ceilings, and the lowest wins:

  1. Window over RTT (section 5): a 16 MB window over a 100 ms cross-region path is 1.3 Gbit/s (derived).
  2. Loss: for loss-based congestion control the long-run rate is about (MSS / RTT) × 1.22 / √p (Mathis et al., 1997): 1,460-byte segments, 100 ms, one loss in 100,000 packets gives 45 Mbit/s (derived), whatever the link. (The old page said 37 Mbit/s: it left out the constant √(3/2) = 1.22.)
  3. Per-flow policy: AWS limits one flow (one 5-tuple) to 5 Gbit/s between instances outside a cluster placement group, up to 10 Gbit/s inside one, and up to 25 Gbit/s between instances in one Availability Zone with ENA Express (EC2 instance network bandwidth).
  4. The NIC and the instance's own bandwidth, shared by all flows.

The first three ceilings are per connection, so parallel connections multiply them until the link is full

Pick a path, then predict how many connections the cross-region preset needs to fill 10 Gbit/s before dragging Parallel connections. Formulas: window / RTT; (MSS / RTT) × √(3/2) / √p; the per-flow cap; the link. illustrative inputs The path presets are typical shapes, not measurements, except the home line, which is this page's measured one.

So the fix is always parallel streams. That is what S3 multipart upload is for (an object split into up to 10,000 parts of 5 MiB to 5 GiB, uploaded concurrently, S3 multipart limits); what PyTorch's Distributed Checkpoint does by having every rank write its own shard ("saving models from multiple ranks in parallel", DCP docs); what s5cmd and rclone do with many concurrent transfers; and why NCCL opens several sockets per peer (section 14). AWS's documentation also lists Multipath TCP and ENA Express as ways past the single-flow cap.

Request rates, not bytes, bound small objects. S3 supports at least 3,500 PUT/COPY/POST/DELETE and 5,500 GET/HEAD requests per second per partitioned prefix (S3 performance). Ten million small image files are a request-rate and latency problem (each GET pays at least a round trip, plus a handshake if the connection is not reused), not a bandwidth one. Pack them into large sequential shards (WebDataset tar files, Parquet, MosaicML's MDS) so each request moves megabytes, spread keys across prefixes, keep connections alive, and prefetch with several workers: the parallel-streams trick again.

A checklist for a slow transfer (five questions, with commands)
A checklist for a slow transfer
  1. Is it one connection? Count with ss -tn dst HOST (Linux) or lsof -nP -iTCP.
  2. Divide the observed rate into window / RTT: if they match, the window binds; raise buffers (and do not set SO_RCVBUF by hand) or add streams.
  3. Retransmissions growing (nstat, ss -ti)? Loss binds: find it (mtr, NIC counters with ethtool -S) or use more streams.
  4. Does it stop at a round number (5, 10, 25 Gbit/s)? A per-flow policy cap.
  5. Is it going through a NAT gateway or out of the region? Use a gateway endpoint for S3, and keep data in the region where it is used.
Recent kernel work on receiving at high rates (depth)

Linux 6.15 added io_uring zero-copy receive (the iou-zcrx documentation was merged then), and devmem TCP lets a NIC place received payloads directly in device memory such as a GPU's. Both cut the CPU cost of receiving at high rates; they matter for ingest and serving rather than for NCCL, which already bypasses the kernel when it uses RDMA.

14. Where TCP still matters in a GPU job

An allreduce moves gigabytes between GPUs every step, and kernel TCP copies each byte from the NIC into kernel memory and then into the application, takes interrupts and backs off on any loss. At hundreds of gigabits per second per node that is too slow and too costly, so the heavy traffic uses RDMA (remote direct memory access: one machine's NIC reads and writes another's memory with no kernel stack copying, and with GPUDirect RDMA straight into GPU memory). It runs on InfiniBand, on RoCEv2 (RDMA inside UDP datagrams to port 4791 over routed Ethernet) and on AWS EFA (the SRD protocol). Each fabric in more detail (the port's IANA registration, where reliability lives, SRD's congestion control), how they are built, their topologies and what each collective costs on them are on Interconnects and scaling, section 4.

TCP is still on the critical path at start-up. NCCL picks NVLink and shared memory inside a server, the IB/RoCE transport across servers, and plain TCP sockets when nothing better exists (NCCL_IB_DISABLE=1 forces that fallback, NCCL environment variables). Even on InfiniBand it sets up its connections over TCP sockets first (the same page's "InfiniBand connection bootstrap sockets"), and PyTorch's rendezvous is a TCP store on MASTER_PORT (29500 unless set, torchrun source). When NCCL does fall back to sockets it opens several per peer, because one TCP connection cannot fill a fast NIC (sections 5 and 13): NCCL_SOCKET_NTHREADS helper threads with NCCL_NSOCKS_PERTHREAD sockets each, defaulting on AWS to 2 and 8, so 16 TCP connections for each network connection between two ranks, the product capped at 64 (same page).

The checklist for a job that hangs at start-up or on its first big collective (wrong interface and the separate GLOO_SOCKET_IFNAME, a firewall that opens only MASTER_PORT, an MTU mismatch, a silent fallback to sockets, the accept queue at the rendezvous rank, a straggler that only looks like the network) is owned by Launching distributed training, section 6; this page explains the TCP and IP behind each (sections 3, 8 and 10). What each collective moves is Distributed training; timeouts and checkpointing at scale are Fault tolerance at scale.

15. Debugging a connection: from symptom to mechanism

Four tools answer most questions, each at a different layer. ping asks whether a host answers and what the round trip is (ICMP echo; some networks drop it, so silence is not proof the host is down). traceroute and mtr show the path and where loss starts (TTL, section 1). ss (Linux; netstat and lsof on macOS) shows every socket's state, queue, window, RTT and retransmissions as the kernel sees them. tcpdump shows the packets themselves (needs root): SYNs resent with no answer, RSTs, window sizes, segments waiting for ACKs, for example tcpdump -ni any 'tcp port 443 and host 203.0.113.5'. Start from what you see:

SymptomMost likely mechanismCommand that shows it
"Connection refused" in under a millisecondnothing listens there, or it listens on another address (section 2)lsof -nP -iTCP:PORT -sTCP:LISTEN; ss -ltnp
Connect hangs, then times outSYN dropped by a firewall or security group (section 3)nc -vz -w 3 host port; mtr host
Connects take 1 s or 3 s instead of millisecondsfull accept queue or lost SYNs (section 8)ss -lnt (Recv-Q against Send-Q); nstat -az TcpExtListenOverflows
"Cannot assign requested address" under loadephemeral ports exhausted by TIME_WAIT (section 3)ss -tan state time-wait | wc -l; fix with pooling
Many CLOSE_WAIT sockets that never go awayyour code does not close connections the peer closed (section 3)ss -tan state close-wait; find the leak
Transfer far below link speed, no retransmissionswindow over RTT (section 5)ss -ti (rtt, cwnd, rcv_space); iperf3 -P 1 against -P 8
Transfer slow with growing retransmissionsloss (sections 4, 6)nstat -az TcpRetransSegs; ethtool -S eth0 for NIC drops
Everything slows while one big transfer runsqueue at the bottleneck: bufferbloat (section 6)ping during the transfer: idle against loaded RTT
Each request about 40 ms slower than it should beNagle plus delayed ACK (section 7)check TCP_NODELAY on both ends
Fails after idle periods with "connection reset"NAT or load-balancer idle timeout (section 9)time since last use against the middlebox's timer; ss -to
Small requests work, big ones hangMTU black hole or mismatch (section 10)ping -M do -s 1472 (Linux), ping -D -s 1472 (macOS); tracepath
HTTP/3 slow or falling back on one networkUDP blocked or UDP buffer drops (sections 11, 12)nstat -az UdpRcvbufErrors; test UDP 443
Distributed job hangs at init_process_groupwrong interface, firewall, MTU (section 14)NCCL_DEBUG=INFO; NCCL_SOCKET_IFNAME
Linux settings you will meet, and reading ss -ti (reference)

Defaults from the current kernel documentation (ip-sysctl, net.core sysctls) and include/net/tcp.h, read 5 October 2026; distributions may override them. This Mac's equivalents are in src/meas/out/env.txt.

SettingDefaultWhat it does, and when to change it
net.ipv4.tcp_congestion_controlchosen when the kernel is built (CUBIC is the default named in RFC 9438 s1); read it, do not assumesender's algorithm; try bbr on long lossy paths (section 6)
net.core.somaxconn4096 (128 before 5.4)cap on any listen() backlog (section 8)
net.ipv4.tcp_rmem / tcp_wmem4K, 131072, up to 32 MB / 4K, 16K, up to 4 MB (depends on RAM)min, initial, autotuning maximum; raise the third value to the BDP for long fat paths (section 5)
net.core.rmem_max / wmem_max4194304 since 6.18 (212992 before)caps explicit SO_RCVBUF/SO_SNDBUF only, not autotuning; matters for UDP and QUIC (section 11)
net.ipv4.ip_local_port_range32768 60999ephemeral ports (section 3)
net.ipv4.tcp_tw_reuse2 (loopback only)1 allows reuse of TIME_WAIT for outgoing connections; pooling is the real fix
net.ipv4.tcp_mtu_probing01 probes when a black hole is detected, 2 always (section 10)
net.ipv4.tcp_slow_start_after_idle10 keeps the congestion window across idle periods on long-lived connections
net.ipv4.tcp_syn_retries6 (about 131 s to give up)shorter connect failure; better: set a connect timeout in the client
keepalive time / interval / probes7200 s / 75 s / 9 (tcp.h)set per socket below the NAT idle timeout (section 9)
TIME_WAIT length60 s, fixed (tcp.h)not tunable; reuse connections

Reading ss -ti. One line per connection: cubic or bbr (algorithm), wscale (send and receive window-scale shifts), rto: (current timer, ms), rtt:x/y (smoothed RTT / variance, ms), mss:, cwnd: (segments), ssthresh:, bytes_acked:, retrans: (in flight / total), pacing_rate, rcv_space: (autotuning's estimate); field list in man 8 ss. Small cwnd with climbing retrans: loss-limited. Large cwnd and a throughput equal to window / RTT: window-limited. The macOS counterpart is netstat -s -p tcp for totals; per-connection detail needs getsockopt(TCP_CONNECTION_INFO), which this page's scripts use.

Reference: drills, interview questions, glossary

Eight predict-then-reveal drills (each from a real situation on this page)
Interview questions, with model answers (optional rehearsal)
What happens, at the transport level, when you call requests.post() to an HTTPS API for the first time?
DNS resolves the name (the DNS page). The kernel picks an ephemeral port and sends a SYN; SYN-ACK and ACK complete the handshake in one round trip, negotiating MSS, window scaling, SACK and timestamps. TLS 1.3 takes one more round trip. The request goes out in one or more segments; the response comes back under flow control (receive window) and congestion control (slow start from 10 segments). The connection is returned to the pool; if it is never reused, whoever closes first holds TIME_WAIT. Total before the first response byte: about three round trips plus server time.
Why can a single TCP connection not use a 10 Gbit/s link across an ocean, and how do you fix it?
Throughput is at most window / RTT. 10 Gbit/s × 100 ms needs 125 MB in flight; a typical autotuning ceiling of a few MB gives tens to hundreds of Mbit/s. Loss caps it further (Mathis: about 45 Mbit/s at one loss in 100,000 with 1,460-byte segments), and clouds cap single flows (5 Gbit/s on AWS outside placement groups). Fixes: raise tcp_rmem/tcp_wmem maxima to the BDP, never pin SO_RCVBUF, consider BBR for lossy paths, and above all use parallel streams (multipart upload, sharded checkpoints).
TCP versus UDP versus QUIC: when do you pick each?
TCP by default for request/response and bulk data between services: reliable, ordered, in the kernel, understood by every middlebox. UDP when late data is useless (media, games), when one packet answers one question (DNS), or as the substrate for your own transport; you must add congestion control. QUIC when you want TCP's guarantees without head-of-line blocking across streams, a combined one-round-trip handshake, and connection migration, typically HTTP/3 to clients on mobile or lossy networks; it costs more CPU and needs a TCP fallback where UDP is blocked.
A service sees thousands of sockets in TIME_WAIT and occasional "Cannot assign requested address". Explain and fix.
The client side closes connections first, so it holds TIME_WAIT for 60 s on Linux; with 28,232 ephemeral ports that allows about 470 new connections per second to one destination address and port. The client is opening a connection per request. Fix: connection pooling with keep-alive (also saves a round trip or two per request). tcp_tw_reuse=1 helps outgoing connections; tcp_tw_recycle no longer exists (removed in 4.12, broke NAT).
Small API calls work but a large upload hangs forever. What do you suspect and how do you prove it?
A path MTU black hole: a smaller-MTU link on the path drops full-size packets, and the ICMP "fragmentation needed" or "packet too big" message is filtered. Prove it with don't-fragment pings of increasing size (ping -M do -s 1472 on Linux): success below a size and silence above it, with no ICMP reply. Fix: allow those ICMP messages, clamp MSS on the tunnel, or enable tcp_mtu_probing.
Why does a streaming endpoint set TCP_NODELAY?
Nagle's algorithm holds a small write while earlier data is unacknowledged. Tokens are small writes 20 to 100 ms apart, so on a real round trip each token after the first would wait for the previous token's ACK (and possibly a 40 ms delayed ACK), turning a smooth stream into bursts. TCP_NODELAY sends each write at once.
How does QUIC survive a phone switching from Wi-Fi to mobile data when TCP does not?
TCP identifies a connection by its 5-tuple, so a new client address matches no socket and the connection is dead; the app must reconnect and redo the handshakes. QUIC identifies it by connection IDs carried in each packet; the server sees the known ID from a new address, validates the new path with PATH_CHALLENGE/PATH_RESPONSE, and continues. This page records exactly that on loopback (section 12).
A pooled HTTP connection fails with "connection reset" only when it was idle for a few minutes. Why?
A NAT gateway or load balancer between the hosts dropped the idle mapping (AWS NAT: 350 s) and answers the next packet with a reset. Neither end was told. Fix: keepalive probes (or application pings) more often than the shortest idle timer, or a pool that discards connections idle longer than it; and retry idempotent requests once on a reset of a reused connection.
Glossary (every term, with its section)
ACK
acknowledgement: "I have every byte up to n" (section 4)
BDP
bandwidth-delay product, link rate × RTT: the bytes that must be in flight to fill a path (section 5)
BBR
congestion control that models bottleneck bandwidth and minimum RTT instead of reacting to loss (section 6)
CIDR, prefix
10.0.0.0/16: all addresses sharing the first 16 bits (section 1)
Congestion window (cwnd)
the sender's estimate of what the network can carry; grows on ACKs, shrinks on loss (section 6)
Connection ID
QUIC's name for a connection, independent of addresses (section 12)
CUBIC
the default congestion control in Linux, Windows and Apple stacks (RFC 9438)
Delayed ACK
a receiver waiting briefly before acknowledging, up to 40 to 200 ms on Linux (section 7)
Ephemeral port
the temporary port the client's kernel picks for its end (section 2)
FIN, RST
orderly close of one direction; abrupt "this connection does not exist" (section 3)
Head-of-line blocking
bytes that arrived waiting behind a missing earlier byte (section 4)
ICMP
IP's control messages: errors such as "time exceeded" and "packet too big", and ping (sections 1, 10)
MSS
maximum segment size: the largest TCP payload per segment, announced in the SYN (section 10)
MTU
maximum transmission unit: the largest IP packet a link carries (section 10)
Nagle's algorithm
holding small writes while data is unacknowledged; off with TCP_NODELAY (section 7)
NAT
network address translation: rewriting private addresses and ports to a public one, with a table of mappings (section 9)
Packet, segment, datagram
an IP unit; a TCP unit inside it; a UDP unit inside it
PMTUD
path MTU discovery, by ICMP "too big" messages or by probing (section 10)
RDMA, RoCEv2, InfiniBand, EFA
direct memory access over the network, and the fabrics that carry it (section 14)
Receive window
free space in the receiver's buffer, advertised in every ACK (section 5)
RTO
retransmission timeout: how long the sender waits before resending (section 4)
RTT
round-trip time: a packet there and the answer back
SACK
selective acknowledgement: which later blocks have arrived (section 4)
Slow start
doubling the congestion window every round trip from 10 segments (section 6)
Socket
the kernel's handle for one end of a conversation (section 2)
SYN
the first segment of a TCP connection, carrying the initial sequence number and options (section 3)
TIME_WAIT
the closed-first side remembering a connection for 2 MSL (60 s on Linux) (section 3)
TTL, hop limit
a per-packet counter each router decrements; at zero the packet is dropped (section 1)
Window scaling
the SYN option that multiplies the 16-bit window field, up to 1 GiB (section 5)
5-tuple
protocol, source address and port, destination address and port: a connection's name (section 2)