IP Addresses
Run ip addr and one line starts inet 192.168.1.42, which looks like four small numbers with dots between them. It is really one 32-bit integer, and its leading bits alone already say whether it can leave your machine at all.
- ▸The dots in
192.168.1.42punctuate a single 32-bit number; its leading bits alone name what kind it is. - ▸Two machines can both answer to
192.168.1.5and neither is wrong, because nothing outside its network routes to that number. - ▸
::may appear only once in an IPv6 address; a second one would leave it ambiguous.
192.168.1.42 looks like four small numbers a person picked. It is one number. The dots are punctuation a machine ignores: underneath, the address is a single 32-bit integer, and each dot marks where one 8-bit slice, an octet, ends and the next begins. Each octet runs 0 to 255, because eight bits count no higher.
Write the address in binary and the four groups become one unbroken row: 11000000 10101000 00000001 00101010. Set the last octet from 42 to 255 and only the final eight bits move; the other twenty-four sit still. You did not change four numbers. You changed one slice of a single integer that was always there under the dots.
A ping to 127.0.0.1 and a ping to 192.168.1.5 never travel the same distance, and you can tell which is which without a lookup. The leading bits decide.
An address whose top bits fall in 10, 172.16 through 172.31, or 192.168 is a private address: real, usable, but meaningful only inside its own network. An address starting 127 is loopback: traffic sent to it turns around inside the host and never reaches a wire. One starting 169.254 is link-local, the address a machine hands itself when it asked the network's DHCP server to lend it an address (a lease) and heard nothing back.
The badge that names each one is not calling a registry. It is reading the front of the number.
Give an address a slash and a number, 192.168.1.0/24, and you have drawn a line through its bits. The number after the slash says how many leading bits name the network; everything to the right names hosts inside it. That is CIDR notation.
A /24 fixes the first twenty-four bits and leaves eight for hosts, so it holds 2^8, or 256 addresses. Slide the cut left to /16 and sixteen host bits remain: 65,536 addresses, two hundred fifty-six times as many. Each bit you hand from network to host doubles the space, because one more bit is one more power of two. A /32 leaves no host bits at all and names exactly one address.
Put 192.168.1.5 on your laptop. Now put 192.168.1.5 on a laptop in another building, on a different network. Nothing breaks. Both are legal, and neither machine is wrong, because a private address is a local name: it means something only on the network it lives on, and the internet carries no route back to it. The two addresses are identical strings that never meet.
Swap one for a public address like 8.8.8.8 and the picture changes: a public address is handed out to one holder on the internet, so a second network that uses it collides with the real holder: its own users reach the copy and never the original. The rule underneath is one line: a private address has no global meaning, which is exactly what makes reusing it safe.