How the Internet works

The Internet Layer, chapter 12 of 36

NAT, CGNAT, and the Middlebox Internet

RFC 1631 proposed NAT in May 1994 as a short-term measure and doubted it even for that, and our SYN still needs it.

Our SYN leaves the laptop from 192.168.1.23, a private address that no router on the Internet will carry back. One hop later, at the home router, eleven of its sixty IPv4 bytes have changed. The server will see 198.51.100.77:40001 and never learn the address the laptop used.

11 of 60
bytes of the SYN's IPv4 packet that differ on the two sides of the home router
22 of 23
home gateways tested in 2025 that kept the source port, where ours picked 40001
150 TB
per month of per-connection CGN logs for a million subscribers

The home router's translation table

Our SYN creates a mapping. Send packets out from the laptop and in from outside, switch the mapping and filtering behavior of RFC 4787, and see which packets get in and what the router rewrites.

How does a NAT fix a checksum without reading the payload?

The IPv4 header checksum covers the header, and the TCP checksum covers a pseudo-header with both addresses (RFC 9293, Section 3.1). A new source address breaks both checksums, and a new port breaks the TCP sum again. Recomputing it would mean reading every payload byte. Because the one's complement sum is commutative, a translator subtracts each old 16-bit word and adds the new one: HC' = ~(~HC + ~m + m') (RFC 1624, Section 3).

Three words change in each header of our SYN. The TTL shares a word with the protocol number, so the decrement is one more term. Linux does the same in csum_replace2() [Linux2026].

Who thought rewriting addresses was a good idea?

Paul Tsuchiya of Bellcore and Tony Eng of MIT, in January 1993. Their paper put a Network Address Translator at the border of each stub domain, and its abstract admitted that "FTP will fail in some but not all cases" [Tsuchiya1993].

RFC 1631 turned the paper into an Informational RFC in May 1994, written by Kjeld Borch Egevang and Paul Francis, as Tsuchiya now called himself. Its conclusion doubts the whole idea: NAT has negative characteristics that "may make it inappropriate even as a short term solution" (RFC 1631, Section 4).

Which mapping does a NAT reuse, and whom does it let in?

An endpoint-independent mapping reuses the external endpoint for every destination. An address-dependent mapping reuses it only for the same remote address, and an address-and-port-dependent mapping only for the same address and port (RFC 4787, Section 4.1). REQ-1 of RFC 5382 requires the first for TCP, because without it the address a host learns from a server outside is useless to any other peer.

Filtering is a separate decision (RFC 4787, Section 5). RFC 5382, Section 4.3 adds connection-dependent filtering, which admits no inbound connection at all. The filtering of Linux NAT is address-and-port-dependent [Linux2026].

Why did FTP hurt so much?

Because FTP writes addresses into its payload. Behind our router, an active-mode PORT command would carry 192,168,1,23, which is twelve characters, and the router would have to write 198,51,100,77, which is thirteen. The segment grows by one octet, so every later sequence number in that direction is off by one and every acknowledgment in the other direction must be shifted back (RFC 3027, Section 4.1).

Linux still has an Application Level Gateway for FTP: nf_conntrack_seqadj.c keeps the offsets. If a segment ends in the middle of a command that the FTP helper recognizes, the helper drops the segment [Linux2026].

What changes when the ISP runs the NAT too?

An ISP short of IPv4 addresses gives the home router a private address and translates a second time in its own network. RFC 6888, Section 2 notes that "carrier-grade" has nothing to do with the quality of the NAT. In April 2012, RFC 6598 reserved 100.64.0.0/10 for the link between home router and CGN, under an IESG note that records "very rough consensus".

One address offers 64,512 ports above 1023 per transport protocol. In 2016 some operators handed out as few as 512 ports per subscriber, and one web page can open many dozens of connections [Richter2016].

How do two hosts behind NATs reach each other at all?

Each asks a server outside what its address looks like and publishes the answer. Both peers then send to each other's reflexive address at about the same time, and each outbound packet opens its own NAT's filter for the other side. In the tests that RFC 5128, Section 4 summarizes, UDP hole punching worked on more than 80 percent of devices.

An address-and-port-dependent mapping defeats the trick, because the port the STUN server saw is not the port used toward the peer. Richter and colleagues found this "symmetric" behavior in 40 percent of cellular CGN networks in 2016 [Richter2016].

laptophome routerCGN in AS64500server src 192.168.1.23:51514src 100.64.0.77:40001src 198.51.100.77:40001
From the book: Our SYN if AS64500 used a CGN: the source endpoint on each hop

The book keeps asking

This chapter has 5,754 words and 12 questions. These 6 are answered only in the book and the audiobook.

  • What did the home router change?
  • How long does a NAT remember a flow?
  • Can two hosts behind the same NAT reach each other through it?
  • Who was behind 198.51.100.77 at that moment?
  • Can an application simply ask the NAT for a port?
  • Is a NAT a firewall, and what else sits on the path?

Open the sources

  • RFC 3022 Traditional IP Network Address Translator (Traditional NAT) 2001, Informational
  • RFC 4787 Network Address Translation (NAT) Behavioral Requirements for Unicast UDP 2007, Best Current Practice, BCP 127
  • RFC 5382 NAT Behavioral Requirements for TCP 2008, Best Current Practice, BCP 142
  • RFC 7857 Updates to Network Address Translation (NAT) Behavioral Requirements 2016, Best Current Practice, BCP 127
  • RFC 6888 Common Requirements for Carrier-Grade NATs (CGNs) 2013, Best Current Practice, BCP 127
  • RFC 8445 Interactive Connectivity Establishment (ICE): A Protocol for Network Address Translator (NAT) Traversal 2018, Proposed Standard
  • RFC 3234 Middleboxes: Taxonomy and Issues 2002, Informational
  • [Linux2026] Linux kernel source tree, v7.4-rc1 (commit 6628e7d4c6b2, 1 November 2026) 2026, free

All 47 documents this chapter cites, each with a link to its publisher and a copy kept here.

The Internet Layer, chapter 13 of 36

Living with Two Protocols

Routing, chapter 14 of 36

Inside One Network: Forwarding, OSPF, and IS-IS

Routing, chapter 15 of 36

BGP: The Protocol That Holds It Together

Routing, chapter 16 of 36

Peering, Transit, and the Money

Routing, chapter 17 of 36

Securing the Routing System

Routing, chapter 18 of 36

MPLS and Segment Routing

Routing, chapter 19 of 36

Anycast and CDNs

Transport, chapter 20 of 36

UDP: Eight Bytes of Header

Transport, chapter 21 of 36

TCP: The Connection

Transport, chapter 22 of 36

Congestion Control: From Collapse to BBR

Transport, chapter 23 of 36

Beyond TCP: SCTP, DCCP, and Multipath

Names and Trust, chapter 24 of 36

DNS: The Namespace and the Wire Format

Names and Trust, chapter 25 of 36

Resolvers, DNSSEC, and Encrypted DNS

Names and Trust, chapter 26 of 36

TLS 1.3: The Handshake

Names and Trust, chapter 27 of 36

Certificates and the Web PKI

Applications, chapter 28 of 36

HTTP: Semantics and HTTP/1.1

Applications, chapter 29 of 36

HTTP/2: Multiplexing over One Connection

Applications, chapter 30 of 36

QUIC: A Transport in Userspace

Applications, chapter 31 of 36

HTTP/3: The Web on QUIC

Applications, chapter 32 of 36

Mail: SMTP and Forty Years of Patches

Applications, chapter 33 of 36

Time, Shells, and Files: NTP, SSH, Telnet, and FTP

The Whole Path, chapter 34 of 36

Measuring and Debugging the Path

The Whole Path, chapter 35 of 36

The Whole Journey, Byte by Byte

The Whole Path, chapter 36 of 36

Ossification and What Comes Next

You have reached the server. The book goes further.

Everything on this site is a short version. Follow the Packet is the long one: 36 chapters and about 280,000 words, with every protocol fact traced to the section of the standard that defines it, every byte dump built by a script you can run, and a directory of more than a thousand cited documents. It comes as a printable book and as an audiobook.

Hear how chapter 1 opens. 70 seconds, narrated by a synthetic voice.

Get the book or the audiobook Read the start of chapter 1 Browse every source

Cover of Follow the Packet: How the Internet Works, Layer by Layer, from ARPANET to QUIC, by Wolfgang Kerschbaumer

The signup uses double opt-in. Every message includes an unsubscribe link.

Published by Sysinit Press. The public addresses, AS numbers and names of the scenario come from ranges reserved for documentation, and the home network uses private addresses, so the site describes no real network. RFC texts are copied unchanged from the RFC Editor.