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.

· 3 min read · beginner

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:

text
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:51000

The 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."

text
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.

Related

Networking beginner

DNS, From Query to Answer

How a name becomes an address — resolvers, the root/TLD/authoritative hierarchy, the record types that matter, and why DNS changes take time.

· 2 min read
Networking beginner

Subnetting Without a Calculator

CIDR notation demystified. Learn the handful of powers of two that let you split and size networks in your head, with a reference table you'll actually remember.

· 1 min read
Networking beginner

What Happens When You Load a URL

The full journey from pressing Enter to seeing a page — DNS, TCP, TLS and HTTP — tied together so every layer finally makes sense.

· 2 min read