The Plain Picture#
Badge numbers (MAC addresses) only work inside one building. To send a letter to any building in the world, you need a postal address — and a postal address has structure: country → city → street → house number. A sorting office in Delhi doesn't need to know every house in Bangalore. It just sees "Bangalore" and sends the letter that way.
The Real Names#
An IP address (Internet Protocol address) is a device's address on the whole internet (the "Internet" layer from Chapter 2).
The version most of the internet still uses is IPv4: an address is 32 bits.
It is written as 4 decimal numbers separated by dots — dotted decimal, like
192.168.1.37. Each number is one byte, so each is 0–255.
Under the Hood#
An IPv4 address is just 4 bytes (How Computers Work Ch 2):
192 . 168 . 1 . 37
1100 0000 1010 1000 0000 0001 0010 0101Check the first byte: 128 + 64 = 192 ✔. The last: 32 + 4 + 1 = 37 ✔.
How many IPv4 addresses exist? 2³² ≈ 4.3 billion. There are more devices than that on Earth (phones, laptops, servers, TVs, cameras). The central pool of unassigned IPv4 addresses ran out in 2011. The internet survives through two tricks: private addresses + NAT (Chapter 6 and the next file), and IPv6 (Chapter 10).
What's in an IP header (the important fields only):
┌──────────────────────────────────────────────────────────┐ │ version (4) │ total length │ │ TTL (time to live, Ch 7) │ protocol (TCP=6, UDP=17) │ │ source IP address (32 bits) │ │ destination IP address (32 bits) │ └──────────────────────────────────────────────────────────┘ followed by the payload (e.g. the TCP header + your data)
Protocol tells the receiver which transport protocol is inside (next file).
TTL stops lost packets from looping forever (Chapter 7).
Public vs private: every device reachable from the internet directly has a public IP address, unique in the whole world. Most devices at home or inside a company instead have a private IP address, which only needs to be unique inside that network (Chapter 6).
See your IP address: on a Mac, ipconfig getifaddr en0. You'll probably see something like
192.168.1.37 — that's private. To see your public address, visit a "what is my IP" site: it'll be
different. That difference is NAT (next file).
Check yourself
4 questionsHow many bits is an IPv4 address? How many bytes?
Show answerHide answer
32 bits, 4 bytes.
Why is each number in 192.168.1.37 between 0 and 255?
Show answerHide answer
Each number is one byte, and one byte holds 0–255.
Write 10.0.0.1 in binary.
Show answerHide answer
00001010.00000000.00000000.00000001.
Why did the world run out of IPv4 addresses?
Show answerHide answer
There are only 2³² ≈ 4.3 billion, and there are more internet-connected devices than that.