How IPv4 Exhaustion and NAT Changed Application Design
· 4 min read
I had a task at work, to implement notifications.
If you see the normal web, you send the request to the server and you receive the response. This is how normal web works.
Well notifications, your phone is notified when something comes up on the server. For servers to notify clients, there are many techniques such as SSE, Long Polling, Short Polling, or WebSockets.
But, I had a different question. What if, just like a client sends a request to a server, a server could send a request directly to the client? Trying to explore this small question helped me discover the history of the Internet, which was truly fascinating.
As we all know, each device when connected to a network is assigned an IP address which identifies it on that network. This seems straightforward until you realise that the Internet is a network of networks.
But before that, a bit of history.
When the idea of computers communicating with each other emerged, its usage was mostly limited to universities, research institutions and the military in the US. At that time, researchers envisioned a network where each host connected to the Internet would have its own globally unique identity, its own IP address, very much like a phone number. Any computer on the Internet could, in principle, connect directly to any other computer. For addressing these hosts, they came up with an addressing system called IPv4. Something like 192.168.0.1, you might have seen.
IPv4 was a great idea and suddenly the Internet was no longer limited to universities and the military. The public started getting a taste of it. But there was a limitation. Each number separated by a period can only range from 0-255, meaning IPv4 can provide roughly 4.3 billion addresses.
There was a concern. Not only was the Internet growing rapidly, but addresses were also being allocated inefficiently in the early days, and the number of devices connecting to the Internet was exploding. Soon, the available IPv4 address space would not be enough.
The long-term solution was simple in theory: introduce a new addressing system that would be large enough to serve the population of Earth and all of their devices. Researchers came up with IPv6, an addressing system capable of supporting around 340 undecillion addresses - an almost unimaginable number.
But migrating the entire Internet ecosystem to a new addressing system was expensive and time-consuming. So engineers came up with another idea.
Most devices connect to the Internet through a router. What if the router had the globally unique address, while the devices behind it used private addresses and the router kept track of who was talking to whom? This idea became known as Network Address Translation (NAT).
Suddenly, instead of every device needing its own public address, many devices could share a single public address through their router. The devices were still communicating with servers on the Internet, but the router would rewrite addresses and keep track of the connections.
This idea dramatically slowed down IPv4 exhaustion. It also had an interesting side effect: devices behind NAT became difficult to reach directly from the Internet unless the router already knew where incoming traffic should go. This unintentionally added a layer of protection for many home networks.
And this is what changed how applications are designed.
For notifications, a server usually cannot initiate a brand new connection directly to a device behind NAT because all it sees is the public address of the router. If the server sends unsolicited traffic to that public address, the router typically won’t know which device should receive it and will drop it unless there is an existing mapping or an explicit port-forwarding rule.
This wonderful history of networking helped me understand why peer-to-peer systems are designed the way they are. Technologies like STUN, ICE, TURN and UDP hole punching exist largely because the original vision of every device having a globally reachable identity became difficult to maintain at Internet scale, and NAT became the practical solution that the world adopted.