Port Forwarding and NAT, Properly Explained
Why your devices share one public IP, what NAT actually rewrites, why inbound connections fail by default, and when (and when not) to open a port.
Port forwarding is one of those topics everyone half-understands from configuring a game server or a security camera. Here is the real mental model.
The problem NAT solves
There are not enough IPv4 addresses for every device. So your ISP gives your router one public address, and every device behind it uses a private address (192.168.x.x, 10.x.x.x, 172.16–31.x.x). Network Address Translation is how the router lets many private devices share that one public IP.
What NAT rewrites
When your laptop (192.168.1.50) opens a connection to a web server, the router rewrites the packet's source so replies come back to the router, and records the mapping in a table:
Outbound: 192.168.1.50:51000 ─▶ [router] ─▶ 203.0.113.9:51000 ─▶ server:443
translation table remembers:
203.0.113.9:51000 ⇄ 192.168.1.50:51000
Inbound: server:443 ─▶ 203.0.113.9:51000 ─▶ [router] ─▶ 192.168.1.50:51000The port number is the key. When the reply arrives, the router looks up the port in its table and knows which internal device to send it to. This is why it is sometimes called PAT (Port Address Translation) or "NAT overload."
Why inbound connections fail by default
The translation table only has an entry because your device reached out first. An unsolicited packet arriving from the internet has no matching entry — the router has no idea who it is for, so it drops it.
Enter port forwarding
Port forwarding is a permanent, manual entry in that translation table:
"Any connection arriving on public port 25565, send it to
192.168.1.50:25565."
Internet ─▶ 203.0.113.9:25565 ─▶ [router rule] ─▶ 192.168.1.50:25565 (your server)Now outsiders can reach that one internal service — because you told the router exactly where to route it. You need this for: self-hosted game/web servers, remote desktop into your LAN, some P2P apps.
Do you actually need to open a port?
Often no, and opening one is the riskiest option because it exposes a service directly to the whole internet. Safer alternatives:
- A reverse tunnel / VPN (WireGuard, Tailscale,
ssh -R) — the internal device dials out and you reach it through the tunnel. No inbound rule, no exposure. - A reverse proxy on a VPS — a public server you already trust relays traffic inward.
- UPnP — lets apps open ports automatically. Convenient, but it means software can expose you without asking; most security-conscious people disable it.
If you do forward a port — the checklist
- Forward to a fixed internal IP (set a DHCP reservation so it doesn't move).
- Expose the narrowest port possible, nothing extra.
- Put a real service behind it — patched, authenticated, ideally TLS.
- Never forward management interfaces (SSH, RDP, router admin) to the whole internet; restrict by source IP or put them behind a VPN.
- Log and watch it. An open port will get scanned within minutes.
Why this connects to security
Understanding NAT explains why malware uses outbound reverse connections (they pass NAT for free) while defenders focus on egress filtering. The same mechanism that lets you host a game server is the one attackers exploit to tunnel out — direction is everything. See the companion piece on how Remote Access Trojans work for the offensive-side picture.
Takeaways
- NAT lets many private devices share one public IP by rewriting ports and remembering the mapping.
- Inbound fails by default because there's no table entry — forwarding adds a permanent one.
- Prefer a VPN or reverse tunnel over opening a port; if you must open one, keep it narrow, patched and watched.