IP, IPv4, IPv6, Subnets, NAT & Ports
Best-effort packet delivery, address structure, CIDR and subnetting, why IPv6 exists, NAT translation tables and what a port really is.
IP is the one protocol every device on the internet speaks: a source address, a destination address, a hop counter and a payload, forwarded hop by hop with no promise of delivery, order or uniqueness — a deliberately thin contract that leaves reliability to the ends and lets routers stay stateless.
`192.168.1.42` is 32 bits split by a mask into a network part that routers care about and a host part that only the last router does; the private ranges, loopback, link-local and broadcast addresses are carved out of the same space, and the space ran out — which is why NAT and IPv6 exist.
IPv6 gives every device a globally routable address and removes NAT as a necessity — but it also redesigns the header, replaces ARP and broadcast with ICMPv6 multicast, lets hosts configure themselves from router advertisements, forbids router fragmentation, and coexists with IPv4 through dual-stack and Happy Eyeballs rather than replacing it.
`10.0.0.0/24` is 256 addresses with 254 usable; move the mask one bit right and it becomes two `/25`s of 128 — subnetting is prefix arithmetic, and it exists to bound broadcast domains, draw security boundaries and let routers aggregate many networks into one route.
An IP address reaches a machine; a 16-bit port reaches one program on it — `203.0.113.10:443` names the HTTPS listener. The 4-tuple of both addresses and both ports identifies a connection, which is why one server port serves thousands of clients and why a client that opens too many connections to one destination runs out of ports.
A NAT rewrites the private source `10.0.0.4:54001` to the public `203.0.113.7:62014` on the way out, records the mapping in a table, and reverses it on the way back — which lets a household or a data centre share one address, and which is the reason inbound connections, peer-to-peer, long-lived idle sockets and high connection rates all need special handling.