Why NAT
IPv4 has about 4.3 billion addresses, too few for every device. So your home gets one public address, 203.0.113.7, on the router. The laptop and phone use private ones (192.168.1.x) that the internet never carries.
Out and back
Your laptop opens a connection to 198.51.100.20, port 443. A port is a number that tells a device which app a packet is for. The packet's source is 192.168.1.10:50000, an address no one outside can send back to.
The router replaces the source with its public address and a free port: 203.0.113.7:61001. It writes the pair in its translation table, so it can undo the swap later.
The rewritten packet crosses the internet. The server sees only 203.0.113.7:61001. It has no idea the laptop exists, or what its private address is.
The server answers the address it saw: 203.0.113.7:61001. The internet can deliver that, because 203.0.113.7 really belongs to your router.
The router looks up port 61001 in its table, finds 192.168.1.10:50000, and writes that in as the destination. The port is the key that says which device gets the reply.
The reply reaches the laptop as a normal answer to 192.168.1.10:50000. The laptop never sees the swap.
Sharing one address
Now the phone talks to the same server. By chance it picks the same source port, 50000. Only its private address differs: 192.168.1.11.
Port 61001 is taken, so the phone gets 61002 and a second row. Both devices share 203.0.113.7; the public port tells their replies apart. This is port translation (NAPT, or PAT).
Limits
A stranger at 192.0.2.99 sends a packet to 203.0.113.7:8080. No row matches, so the router drops it. To run a game server or camera at home, you add a fixed row by hand: port forwarding.
Rows are deleted when a conversation ends or sits idle: after at least 2 minutes for UDP (a simpler, connection-free cousin of TCP), and 2 hours 4 minutes for an open TCP connection. IPv6 has enough addresses for every device, so it needs no NAT.
The headers, field by field
;; step 1/11 · one-address · local ;; at home router + laptop + phone IPv4 addresses: 2^32 = 4,294,967,296 (RFC 791) home LAN 192.168.1.0/24 · private space, RFC 1918: 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 laptop 192.168.1.10 · phone 192.168.1.11 · router inside 192.168.1.1 router outside: 203.0.113.7 (the one public address) private addresses are not routed on the public internet, so the router must translate: NAT (RFC 3022)
Many routers keep the inside port when it is free (port preservation, RFC 4787 §4.2.1). Here the router hands out 61001, 61002, … so the swap is easy to see. Real routers also note the server’s address and port in each row and may accept replies only from it (RFC 4787 §5).