Private and Public IP, and NAT

Network Layer · 25 min

Core CS · Computer Networks

Your address is not the address the Internet sees

Your laptop says 192.168.1.10. A website says you came from somewhere else entirely. One box on the border of your network rewrites the first into the second, writes down what it did, and undoes it on the way back. Watch it happen field by field.

Watch three hosts share one public address, step by step
A private address is not globally unique and not globally routable, and those are the same fact: it can be reused in every network on earth because routers on the public Internet drop it. NAT is the border device that rewrites it into a public address on the way out and back again on the way in. PAT rewrites the source port as well, and that port number is the only thing that tells the return traffic apart.

01 The idea

There were never enough addresses to go round

An IPv4 address is 32 bits. That fixes the entire supply at 2³² = 4,294,967,296, about 4.3 billion, for every phone, laptop, server, router, camera and card machine on the planet. It is worse than that number suggests, because large blocks were carved out and can never be assigned to a host on the Internet: 127.0.0.0/8 is loopback, 224.0.0.0/4 is multicast, 240.0.0.0/4 is reserved. IANA handed the last of its free blocks to the regional registries on 3 February 2011. There has been no free pool since.

Now put that number next to the world it has to cover. There are more active mobile connections on the planet than there are IPv4 addresses in existence, before you count a single laptop, server, printer or router. So the address on the machine in front of you cannot be one of those 4.3 billion in any exclusive sense, and it is not. Run ipconfig or ip addr and you get something like 192.168.1.10. Open a page that reports your address and you get a completely different number. Two addresses, one machine, and nothing is broken. This lesson is about which is which, and about the box that turns one into the other.

The first half of the answer is RFC 1918. It sets aside three blocks of address space that anybody may use inside their own network without asking anybody, on one condition: those addresses are not allowed onto the public Internet. Every router in the middle of the Internet is configured to drop a packet whose destination is one of them. That is the whole deal, and it is a trade rather than a gift. You give up being reachable from outside, and in exchange you get an unlimited local supply that nobody has to allocate to you. Because they are dropped out there, they can be reused everywhere in here. Your college, your hostel Wi-Fi and a bank in Frankfurt can all be running 192.168.1.1 right now, and none of them collide, because no packet carrying that address ever crosses between them.

The second half is NAT, Network Address Translation. Something has to stand on the boundary and rewrite, because a packet with a private source address can leave your network but nothing out there can answer it. So the border router rewrites the source address of every packet on the way out, remembers what it did, and rewrites the destination address of every reply on the way back in. In its plainest form that is one private address swapped for one public address, which conserves nothing. The version that actually runs everywhere rewrites the source port number too, and that single extra field is what lets three hundred machines share one public address, because the port is what tells their replies apart.

Private addresses are reusable everywhere precisely because the public Internet refuses to carry them. NAT rewrites the source address on the way out and the destination address on the way back, and stores one row per flow so it can undo exactly what it did. PAT adds the source port to what it rewrites, and that port is the field doing the disambiguation.
Private addressAn address from one of the three RFC 1918 blocks: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. Unique only inside one network, never routed on the public Internet, and free to reuse. Not the same thing as a link-local 169.254.x.x address, which nobody assigned at all.
Translation tableThe router’s record of what it rewrote, one row per flow. Cisco names the columns inside local, inside global, outside local and outside global. It is live state held in memory, not configuration: a dynamic row is created by the first packet of a flow and deleted when the flow goes quiet.
PATPort Address Translation, also called NAT overloading and defined as NAPT in RFC 3022. It rewrites the source port along with the source address, so the pair (public address, public port) identifies one inside flow. This is the NAT in your home router, your phone hotspot and your college gateway.

02 Worked example

One packet, two source addresses, and only one of them survives the border

This is the scene for the rest of the lesson, including the console in section 04 and every address in the cheat sheet. One office network, 192.168.1.0/24, mask 255.255.255.0. Three machines on it, one router on the border, and exactly one public address for the whole office. All three machines are about to open a connection to the same web server, on the same port 80, which is the case that makes port translation necessary rather than merely convenient.

DeviceAddressKind of addressReachable from the Internet?
Host 1192.168.1.10private, RFC 1918no
Host 2192.168.1.11private, RFC 1918no
Host 3192.168.1.12private, RFC 1918no
Router, inside interface192.168.1.1private, and the default gatewayno
Router, outside interface203.0.113.5public, globally uniqueyes
Web server198.51.100.7:80public, globally uniqueyes

Follow one packet from Host 1, left to right. Watch what changes in it and what does not.

The host builds a packetSource 192.168.1.10, source port 50000 chosen from its own ephemeral range, destination 198.51.100.7 port 80. Masking the destination with /24 gives 198.51.100.0, not 192.168.1.0, so it is off-link and goes to the default gateway.
Inside interface, 192.168.1.1The router receives a perfectly ordinary packet. If it forwarded this unchanged, the packet would arrive and the reply would have nowhere to go: no router on the Internet holds a route to 192.168.1.10, because millions of hosts have that address.
Translate, and write the rowSource becomes 203.0.113.5:50000. Destination is untouched. One row is written so the reverse is possible: 192.168.1.10:50000 maps to 203.0.113.5:50000 for this destination. Nothing above the transport layer is looked at.
The public InternetEvery router here has a route towards 203.0.113.5 and none towards 192.168.1.10. The packet is now ordinary public traffic. Its original source address does not exist anywhere in it any more, in any header.
The server repliesIt sends to 203.0.113.5:50000, the only address it has ever seen. The reply reaches the router, the row is found by that port, the destination is rewritten back to 192.168.1.10:50000, and Host 1 receives it having noticed nothing.

Two things in the highlighted node are worth slowing down on, because both get answered wrongly under pressure. First, only the source is rewritten on the way out. The destination 198.51.100.7:80 is carried through untouched, which is why the server sees a normal request to itself. On the way back the mirror holds: only the destination is rewritten, and the server’s address is untouched. Second, the row is written before the packet is forwarded, not after. It has to be, because the reply can arrive within milliseconds and the router has no other way to know where it belongs.

Now make it three hosts instead of one, and the reason for the port comes out. Host 1, Host 2 and Host 3 all connect to 198.51.100.7:80. Each picks its own source port, and a source port only has to be unique on the host that picked it. Nothing coordinates the three machines, so it is entirely legal, and quite likely, that two of them pick the same number. Say Host 1 and Host 2 both choose 50000.

If the router rewrote only the address, all three packets would leave with source 203.0.113.5 and two of them would leave with source port 50000. The server would then send two replies to 203.0.113.5:50000, and the router would have two rows matching the same public port and no way to choose between them. That is not a rare edge case; with hundreds of hosts it is a certainty. So the router does the only thing that works: when the public port it would like is already in use, it allocates a different one, writes that into the row, and rewrites the packet to match. Host 1 keeps 50000 because it asked first, Host 2 is moved to 50001, and Host 3 keeps 51234 because nothing else wanted it.

Count what the server sees at the end of that: one source address, three source ports, and no way whatsoever to tell that there are three machines rather than one very busy one. Count what the router holds: three rows and three public ports in use out of a 16-bit space. The port field, which was invented so one host could run many conversations, is being used here so one address can serve many hosts. That reuse is the whole trick, and it is what section 04 walks through one packet at a time.

03 Mechanics

The three ranges, the three flavours of NAT, and what it costs

Start with the ranges, because every question on this topic begins by asking whether an address is private, and one of the three is stated wrongly more often than it is stated correctly. Work each one from the mask rather than from memory: the network address is the address ANDed with the mask, the last address is the address ORed with the inverted mask.

BlockMaskFirst addressLast addressHow manyClassful equivalent
10.0.0.0/8255.0.0.0 10.0.0.010.255.255.255 24 host bits, 2²⁴ = 16,777,216 one Class A network
172.16.0.0/12255.240.0.0 172.16.0.0172.31.255.255 20 host bits, 2²⁰ = 1,048,576 16 contiguous Class B networks, 172.16 to 172.31
192.168.0.0/16255.255.0.0 192.168.0.0192.168.255.255 16 host bits, 2¹⁶ = 65,536 256 contiguous Class C networks
169.254.0.0/16
link-local, RFC 3927, not RFC 1918
255.255.0.0 169.254.0.0169.254.255.255 16 host bits, 2¹⁶ = 65,536 self-assigned; no router forwards it, not even yours
100.64.0.0/10
carrier-grade NAT, RFC 6598
255.192.0.0 100.64.0.0100.127.255.255 22 host bits, 2²² = 4,194,304 shared space for an ISP, not for you

The 172 block, bit by bit, because this is the one that gets marked wrong. A /12 mask is 255.240.0.0, so the boundary falls in the middle of the second octet: eight fixed bits in the first octet and four more in the second. Write it out. 172 = 10101100 and 16 = 00010000, so the fixed part is 10101100 0001. To get the last address, set every remaining bit to one: 10101100 00011111 . 11111111 . 11111111, and 00011111 = 31. So the block runs 172.16.0.0 to 172.31.255.255, not to 172.16.255.255 and not to 172.32.255.255. Test the two neighbours the same way. For 172.15.255.254: 15 = 00001111, ANDed with 11110000 gives 00000000, so its /12 network is 172.0.0.0, which is not 172.16.0.0. Public. For 172.32.0.1: 32 = 00100000, ANDed with 11110000 gives 00100000, so its network is 172.32.0.0. Also public. The private block is the sixteen values 16 to 31 in that octet and nothing else. Across all three RFC 1918 blocks that is 16,777,216 + 1,048,576 + 65,536 = 17,891,328 addresses, roughly four tenths of one per cent of the IPv4 space, reused by everybody at once.

And the one that means something has failed. 169.254.0.0/16 is link-local, from RFC 3927, and Microsoft’s name for it is APIPA. A host uses it when it asked DHCP for an address and got no answer: rather than sit with no address at all, it picks one at random from that range, ARPs to check nobody else has it, and keeps it. It is not a private address in the RFC 1918 sense, and the difference is not pedantry. An RFC 1918 address is administered and your own router will happily route between two RFC 1918 subnets. A link-local address is self-assigned and scoped to a single link, so no router forwards it anywhere, including yours, and a host holding one has no default gateway. RFC 3927 also reserves the first and last /24 of the block, leaving 169.254.1.0 to 169.254.254.255, which is 254 × 256 = 65,024 usable addresses. Seeing one of these on a machine is a diagnosis, not a configuration.

That is the address space. Now the box that bridges it. There are three flavours and interviewers ask you to separate them, so keep the middle column straight: what does it rewrite, and how many inside hosts can be active per public address.

FlavourWhat it rewritesThe mappingInside hosts per public addressWhat it is actually for
Static NATsource address outbound, destination address inbound one private address to one public address, fixed, configured by hand, and it exists before any traffic does 1 publishing an inside server. It is the only flavour where an outsider can start the conversation, because the row is already there.
Dynamic NATsource address outbound, destination address inbound one private address to one public address taken from a pool, allocated on the first packet, returned to the pool on timeout 1 at a time a site with fewer public addresses than hosts but not far fewer. When the pool is empty the next host is refused outright.
PAT
NAT overloading, NAPT
source address and source port outbound; destination address and port inbound (private IP, private port) to (public IP, public port), allocated per flow thousands every network you have ever used. This is what people mean when they say “NAT” without qualifying it.

Why the pool runs out and the port range does not. Dynamic NAT with a pool of four public addresses supports four concurrent inside hosts, full stop, however little traffic each is sending. PAT with one public address is bounded by the port space instead, and a port is 16 bits, so there are 2¹⁶ = 65,536 values per transport protocol per public address, of which port 0 is not used. Routers allocate from the ephemeral range rather than the whole space: IANA designates 49152 to 65535 as the dynamic range, Linux defaults to 32768 to 60999 in net.ipv4.ip_local_port_range, and Windows uses the IANA range. That is why the middle row of the table caps at one and the bottom row is measured in thousands, from exactly the same number of public addresses.

Cisco’s four names for the four addresses in a row are worth memorising, because show ip nat translations prints all four on every line and half the confusion on this topic is people meaning different things by “the outside address”.

TermWhich addressIn the section 02 sceneThe point
Inside localthe inside host, as the inside sees it192.168.1.10:50000the private address. Never appears in a packet outside the border.
Inside globalthe inside host, as the outside sees it203.0.113.5:50000the public address the router lends it. This is the column an arriving reply is matched against.
Outside localthe outside host, as the inside sees it198.51.100.7:80equal to outside global here, because nothing is translating the far end.
Outside globalthe outside host, as the outside sees it198.51.100.7:80the server’s real address. The two outside columns only differ when a second NAT is in the path.

Read “local” as inside-facing and “global” as outside-facing, and “inside” and “outside” as whose address it is. Inside global is therefore the inside host wearing a public address, which is the one people get wrong by reading it as the router’s own. It is not: it is this flow’s loan of the router’s address and one of its ports, and it is released when the flow goes quiet.

Now the honest part, which is the half that separates a good answer from a recited one. NAT solves the address problem by breaking something the Internet was designed around, and the breakages are specific.

The end-to-end model is gone. IP was designed so any host could address any other host directly, and so that routers in the middle only looked at the destination address. A NAT reads and rewrites the transport header, so it is no longer a router in that sense; it is a device that has to understand your connections. Two consequences follow. Addresses are no longer meaningful end to end, so a packet’s source address means “this NAT” and not “this host”. And the NAT holds state that neither endpoint holds: pull its power and the connections die even though both endpoints are perfectly healthy.

Unsolicited inbound traffic has nothing to translate to. A packet arriving from outside is matched against the inside global column. If no row matches, the router cannot rewrite the destination, because there is no correct answer to rewrite it to, so it drops the packet. That is why running a game server or an SSH daemon on a machine behind a home router and handing a friend the address does not work. Two things exist to work around it. Port forwarding is static NAT applied to one port: you configure in advance that 203.0.113.5:22 maps to 192.168.1.10:22, so the row exists before the traffic does. NAT traversal is the automatic version, and it works by having both sides send outward first so that both routers write rows, then getting them to reuse those rows. A STUN server (RFC 8489) with a public address tells a host what public address and port its own router assigned it, which the host cannot otherwise discover; TURN (RFC 8656) relays the traffic when that fails; ICE (RFC 8445) is the procedure that tries the options in order. This is the machinery underneath every video call you have made.

Protocols that carry addresses inside their payload need help. NAT rewrites headers. It does not read your data, so any protocol that writes an IP address or a port into its payload will hand the far end a number that stopped being true at the border. Active-mode FTP is the standard example: the client sends a PORT command containing its own address and a port for the server to connect back to, and after translation that address is a private one the server cannot reach. SIP does the same inside SDP for voice calls. The workaround is an ALG, an application-level gateway, which is the NAT reaching into the payload and rewriting the number there too, and it is fragile by construction. IPsec is worse: the AH protocol authenticates the IP header including the addresses, so any rewrite invalidates it and AH cannot pass through a NAT at all. ESP survives only with NAT traversal, which wraps it in UDP on port 4500 while IKE negotiates on UDP 500.

NAT is address conservation. The privacy is a side effect and it is not a firewall. Say this plainly in an interview, because the opposite is a very common claim. It is true that inside hosts are not directly reachable and that their addresses do not appear on the Internet. But a NAT inspects nothing, filters nothing on the way out, and knows nothing about what a connection is carrying. Any inside machine can open any outbound connection to anywhere, which is how essentially all modern malware communicates, and a payload arriving on a connection the inside host requested is delivered without a second look. A stateful firewall enforces a policy about what is allowed; a NAT drops unmatched inbound packets because it has no answer, which is a side effect of bookkeeping rather than a decision. Relying on it as security is the mistake, and the honest sentence is that NAT bought the IPv4 Internet decades of extra life at the cost of the end-to-end model.

Which is why IPv6 removes the need for it. An IPv6 address is 128 bits, giving 2¹²⁸, about 3.4 × 10³⁸ addresses, so there is no scarcity to conserve and every host can hold a globally unique address again. IPv6 deployments use a stateful firewall for the inbound blocking rather than a translator, which is the correct tool for that job and always was. One thing to know for the meantime: when even an ISP runs short of public addresses it puts a second NAT of its own in front of yours and gives your router an address from 100.64.0.0/10, which is called carrier-grade NAT. Both your outside columns are then translated by somebody else, port forwarding on your router stops working entirely, and that is the situation on most Indian mobile data connections today.

05 Cheat sheet

Thirteen answers to have ready

Every row is something you can be asked to state or compute in under ten seconds. The right-hand column is the specific wrong answer that gets given, not a general caution.

What they askThe answerThe trap
Size of an IPv4 address and the total supply32 bits, 2³² = 4,294,967,296Quoting 4.3 billion as if all of it were assignable. Loopback, multicast and reserved blocks are carved out of that total.
The three private ranges10.0.0.0/8 · 172.16.0.0/12 · 192.168.0.0/16writing the middle one as 172.16.0.0/16 so it stops at 172.16.255.255
Where the 172 block ends172.31.255.255saying 172.32.255.255 — 172.32.0.0 is public address space
How many addresses in each block2²⁴ · 2²⁰ · 2¹⁶ = 16,777,216 · 1,048,576 · 65,536Guessing instead of counting host bits. The exponent is 32 minus the prefix length, every time.
Usable hosts on a /242⁸ − 2 = 254answering 256 — the all-zeros network address and the all-ones broadcast address are not assignable
What 169.254.x.x meanslink-local, RFC 3927, self-assigned because DHCP did not answerCalling it private. It is a different thing, from a different RFC, and no router forwards it including your own.
What plain NAT rewritessource address going out, destination address coming backSaying it rewrites both addresses in every packet. The far end’s address is never touched.
What PAT rewrites in additionthe source portforgetting the port — and then being unable to explain how the reply finds the right host
The four Cisco termsinside local, inside global, outside local, outside globalReading inside global as the router’s own address. It is the inside host wearing a public address for one flow.
Which field disambiguates the return trafficthe inside global portsaying the private IP address — it never appears in any packet on the public side
How many flows one public address supports under PATbounded by the port space: 2¹⁶ values per transport protocolAnswering “unlimited”. It is large, not infinite, and the practical range is narrower than the full 16 bits.
Why an unsolicited inbound connection failsno row matches, so there is nothing to translate the destination into“the firewall blocks it” — there may be no firewall in the path at all
Carrier-grade NAT space100.64.0.0/10, RFC 6598, 100.64.0.0 to 100.127.255.255Filing it under RFC 1918. It is shared space assigned by an ISP, and you never choose it.
Reusable because it is droppedA private address can be used in every network on earth for exactly one reason: routers on the public Internet discard it. Not globally unique and not globally routable are the same property stated twice, and the trade is local supply in exchange for external reachability.
The port is doing the workUnder PAT the address is identical in every row, so it cannot separate anything. Only the inside global port is unique per flow, which is why an arriving reply is matched on the port and why two hosts that chose the same private port cannot both keep it.
Conservation, not securityNAT was built to stretch a 32-bit address space, and the fact that outsiders cannot start a connection is a side effect of having no row to translate to. It inspects nothing and restricts nothing on the way out, so it is not a substitute for a firewall.

06 Where & why

The translation table is a command you can run today

None of this is a teaching abstraction. Every system below prints the same table with different column names, and the limits quoted are documented defaults you can look up in the product that ships them.

Linux · iptables and conntrack
One rule turns a laptop into the router from section 04

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE is PAT in a single line; MASQUERADE is the variant that takes whatever address the outgoing interface currently has, which is what you want on a link whose public address changes. The translation table lives in the kernel’s connection tracker and conntrack -L prints it, one line per flow with both address and port pairs. It is finite and it is tunable: net.netfilter.nf_conntrack_max caps the number of rows, and a busy gateway that hits that cap starts dropping new connections while old ones keep working, which is a genuinely confusing failure to diagnose.

Cisco IOS
The four column names come from here

ip nat inside source list 1 interface GigabitEthernet0/0 overload configures exactly the scene in section 04, and the word overload is what turns dynamic NAT into PAT. show ip nat translations then prints Pro, Inside global, Inside local, Outside local and Outside global, which is where those four terms in your interview come from. Static NAT is a separate statement, ip nat inside source static, and the difference is visible in the output: a static row is present with no traffic at all, while dynamic rows appear on the first packet and age out on a timer.

AWS VPC · NAT Gateway
Private subnets are RFC 1918 by design

You give a VPC a private CIDR block such as 10.0.0.0/16, and instances in a private subnet get addresses from it and no route to the Internet Gateway. A NAT Gateway placed in a public subnet gives them outbound access with the same one-way property as your home router: they can reach out, nothing can reach in. AWS documents the ceiling in the terms of this lesson, up to 55,000 simultaneous connections to each unique destination, and the way past it is more destinations or more addresses rather than a bigger box. Inbound access needs a load balancer or a public address, which is static NAT wearing a cloud name.

Jio · Airtel mobile data
Your router is behind somebody else’s NAT

Log into a home router on a mobile connection and the WAN address is often something like 100.94.13.7, inside 100.64.0.0/10. That is RFC 6598 shared space, not RFC 1918 and not public, and it means the ISP is running carrier-grade NAT with your traffic translated a second time upstream. The practical consequence is immediate: port forwarding configured on your own router does nothing, because the row you created is on the wrong translator, and the address the outside world would have to aim at is not yours to configure. It is also the clearest demonstration in daily life that address exhaustion is a live constraint and not a story about 2011.

The division of labour, in one line to be able to defend on the spot. The private address makes local supply unlimited, because the public Internet drops it. NAT rewrites it at the border and stores one row so the reply can be undone. The port in that row is what tells hundreds of hosts apart behind a single address. Everything else in this lesson, port forwarding and STUN and the FTP gateway and IPv6, is a consequence of that third sentence.

07 Interview questions

What they ask, and what they follow up with

This topic has one favourite follow-up: you explain NAT, and the interviewer asks how the reply gets back to the right machine. Everything else is a range you either know exactly or do not. Say the numbers, then say the mechanism.

What is the difference between a private and a public IP address?
A public address is globally unique and globally routable: exactly one machine on the Internet holds it, and routers everywhere know how to reach it. A private address is neither, and the two facts are linked. Routers on the public Internet are required to drop packets addressed to RFC 1918 space, which is precisely what makes the same address safe to reuse in millions of separate networks at once. So a private address identifies a host only within one network, and it has to be translated at the border before its traffic can go anywhere else.
Give me the private address ranges exactly.
Three blocks from RFC 1918. 10.0.0.0/8, which is 10.0.0.0 to 10.255.255.255 and 2²⁴ = 16,777,216 addresses. 172.16.0.0/12, which is 172.16.0.0 to 172.31.255.255 and 2²⁰ = 1,048,576 addresses. And 192.168.0.0/16, which is 192.168.0.0 to 192.168.255.255 and 2¹⁶ = 65,536. The middle one is the one people get wrong: a /12 mask is 255.240.0.0, so the boundary sits inside the second octet and only the values 16 to 31 are private. 172.15.x.x and 172.32.x.x are both public.
Two different colleges both use 192.168.1.1 for their gateway. Is that a conflict?
Not at all, and it is the intended behaviour. An address only has to be unique inside one routing domain, and no packet carrying 192.168.1.1 ever crosses between the two colleges, because the routers in between drop it. It becomes a real problem only when the two networks are joined, for example by a site-to-site VPN or a company merger, and then the overlapping subnets have to be renumbered or double-NATed so each side sees the other under a different range. That is the standard argument for planning your internal addressing out of 10.0.0.0/8 rather than the default 192.168.1.0/24 everybody ships with.
A laptop shows 169.254.4.19. What does that tell you?
That it asked a DHCP server for an address and got no reply, so it assigned itself one from the link-local range 169.254.0.0/16, which RFC 3927 defines and Microsoft calls APIPA. It is not a private address in the RFC 1918 sense and calling it one is a mistake: an RFC 1918 address is administered and can be routed between subnets inside your own network, while a link-local address is self-assigned and scoped to a single link, so no router forwards it anywhere. A host holding one also has no default gateway, because a gateway is something DHCP would have told it about.
What problem does NAT actually solve?
Address exhaustion. IPv4 addresses are 32 bits, so the entire supply is 2³² = 4,294,967,296, and IANA gave out the last free blocks in February 2011. NAT lets an arbitrary number of hosts behind a border device share a small number of public addresses, by rewriting the source address of every outbound packet and the destination address of every reply. Everything else people attribute to it, including hiding internal topology, is a side effect of that rewriting rather than a design goal.
Static NAT, dynamic NAT and PAT. Separate them for me.
Static NAT is one private address permanently mapped to one public address, configured by hand, and the mapping exists before any traffic does, which is why it is the only one that lets an outsider start the conversation. Dynamic NAT does the same one-to-one mapping but takes the public address from a pool on the first packet and returns it on timeout, so the number of simultaneously active inside hosts can never exceed the pool size. PAT, also called NAT overloading, rewrites the source port as well as the source address, so the unique key becomes the pair of public address and public port rather than the address alone. Only PAT genuinely conserves addresses, and it is what runs in every home router.
Three machines behind one public address all connect to the same web server on port 80. How does a reply find the right machine?
By the port the router assigned, not by the address. All three flows leave with the same source address, so the address separates nothing on the way back; what distinguishes them is the inside global port. When a reply arrives, the router looks its destination port up in the inside global column of the translation table, finds one row, and rewrites the destination address and port to the inside local pair from that row. It follows that two inside hosts cannot both keep the same source port, so when they pick the same number the router moves one of them, and that rewrite is the entire reason the return path is unambiguous.
What do inside local, inside global, outside local and outside global mean?
Read “inside” and “outside” as whose address it is, and “local” and “global” as which side of the border is looking at it. Inside local is the inside host as the inside sees it, the private address. Inside global is the same host as the outside sees it, the public address and port it has been lent for this flow. Outside local and outside global are the far host as seen from each side, and they are equal unless a second NAT sits in the path. The one that gets misread is inside global, which is not the router’s own address in the abstract but this specific flow’s claim on it.
Is NAT a firewall?
No, and saying so is the answer they are listening for. NAT drops unsolicited inbound packets because no row matches them and there is therefore no address it could rewrite the destination into, which is a consequence of bookkeeping rather than a policy decision. It inspects nothing, it applies no rules, and it does not restrict outbound traffic at all, so any inside machine may open any connection to anywhere. A stateful firewall decides what is permitted and can say no; a NAT only ever says “I have no idea where this goes”. Treating the second as the first is how networks end up with no egress filtering whatsoever.
Which protocols break under NAT, and why?
Anything that writes an IP address or a port into its own payload, because NAT rewrites headers and does not read data. Active-mode FTP is the classic case: the client puts its own address and a port inside a PORT command, and after translation the server is told to connect back to a private address it cannot reach. SIP does the same thing inside SDP. The workaround is an application-level gateway that reaches into the payload and rewrites the number there too, which is fragile by construction. IPsec AH cannot pass a NAT at all, because it authenticates the IP header including the addresses, and ESP needs NAT traversal, which wraps it in UDP on port 4500 while IKE runs on UDP 500.
Does IPv6 need NAT?
No. An IPv6 address is 128 bits, giving about 3.4 × 10³⁸ addresses, so there is no scarcity to conserve and every host can hold a globally unique address again, which restores the end-to-end model NAT broke. A translation form called NPTv6 exists for renumbering, but it is not required and is not deployed the way IPv4 NAT is. The inbound blocking people liked is done by a stateful firewall instead, which is the right tool for it and always was: a firewall enforces a policy, whereas NAT was only ever dropping packets it could not resolve.

08 Practice problems

Six to work out on paper

For every one: write the addresses in binary before you decide anything, and keep the mask you are applying labelled, because two of these apply two different masks to the same address for two different reasons. Where a count is asked for, say whether you are counting addresses or usable hosts.

Two masks, one address

Easy
A host is configured 172.20.130.45 with mask 255.255.240.0. Give the network address, the last address of that subnet, and the number of usable host addresses on it, all worked in binary. Then say whether the address is private, showing the separate operation that decides it.
Follow-up
The mask that defines the subnet and the mask that decides privacy are two different masks, and they give two different network numbers for the same address. Getting the subnet right tells you nothing about the second answer.
Show the hint
Do the two ANDs on separate lines and label each one. The privacy test ignores the configured mask entirely and looks only at the top four bits of the second octet.

The laptop that gave up

Easy
An office laptop on a wired LAN shows 169.254.87.3, mask 255.255.0.0, and no default gateway. Say whether it can reach (a) a second laptop on the same switch showing 169.254.201.90, (b) a printer on the same switch at 192.168.1.20, and (c) 8.8.8.8. Justify each answer from the mask, and name the one thing that has to be fixed.
Follow-up
Two of the three answers are the ones people expect and the first one is not. Two machines that have both apparently failed can talk to each other perfectly well, which is exactly why this fault gets misdiagnosed as a cable problem.
Show the hint
Mask each destination and ask two separate questions about it: is it on my link, and if it is not, do I have a next hop to send it to. A link-local address is not a broken address, it is an address with a deliberately tiny scope.

Four hosts, three of them stubborn

Medium
Four inside hosts behind one public address 203.0.113.5 each open a connection to 198.51.100.7:80. Their chosen source ports are 50000, 50000, 50000 and 40000. Give a valid set of four inside global port values, state the minimum number of source ports the router is forced to rewrite, and explain what specifically goes wrong if it rewrites none of them.
Follow-up
The minimum is smaller than the number of hosts that chose the same port, and one of the four flows was never a problem in the first place. The router is not trying to rewrite as much as possible.
Show the hint
The constraint is on the pair of public address and public port, not on the private port. Ask how many rows may hold the same pair before the return path stops having a single correct answer.

State versus configuration

Medium
The router in section 02 is power-cycled while all three hosts have live connections open to the web server. Say what happens to the translation table, what each of the three hosts experiences, and what would have been different if Host 1 had been covered by a static NAT entry instead of a dynamic PAT row.
Follow-up
Nothing about the three connections themselves has changed. Both endpoints stay powered on and healthy, the server never notices anything, and yet neither end holds the piece of information that went missing.
Show the hint
Ask where the translation table physically lives, and whether anything other than the router holds a copy of it. Then ask which kind of row is rebuilt at boot from a configuration file and which kind is not.

Two friends, both behind NAT

Medium
Two students on different home broadband connections want a direct peer-to-peer file transfer. Each machine is on 192.168.1.x behind a router with a single public address. Explain why handing each one the other’s address and telling them to connect does not work, and describe what has to happen before a direct connection between them is possible at all.
Follow-up
This is not one problem but two, and they fail at different places for different reasons. Fixing only the address half leaves the other half exactly as broken as it was.
Show the hint
Write down separately what is wrong with the address your friend gives you, and what is wrong with your packet at the moment it reaches their router. The two failures need two different fixes, and one of them needs a third machine that is not behind a NAT.

How large is thousands

Hard
A single public address 203.0.113.5 does PAT for an office. Compute the number of simultaneous TCP flows it can support if the router allocates only from the IANA dynamic range 49152 to 65535, and again if it may allocate anything from 1024 to 65535. Then explain how an office of 300 people can exceed the first number in ordinary use, and what changes if the router keys each row on the destination address as well as the port.
Follow-up
The second number is close to four times the first, and it is still not the real ceiling. What lifts it is not a larger port range but a wider key, and that same change is what makes some NATs almost impossible to traverse.
Show the hint
A port is 16 bits, so start from 2¹⁶ and subtract carefully, keeping the two ranges in separate columns. Then write out every field the router could store in one row and count how many of them have to be unique for the return path to stay unambiguous.