Every device gets an address.
Open your phone's Wi-Fi settings and tap your home network. Somewhere on that screen is a line like 192.168.1.7. Now ask a friend in another city to do the same. There's a fair chance their phone shows 192.168.1.7 too.
Two phones, two cities, the same number. So how does a reply ever find the right one?
See it#
Look inside one home. A phone and a laptop sit on the same Wi-Fi, and one box joins them to the internet: the router. Watch which number each device uses, and which number the rest of the world sees.
Many numbers inside, one number outside.
Every device in the house got its own number from the router, and those numbers all start the same way. But when any of them talks to the internet, the outside world sees just one number: the router's. The house has many numbers inside and one number outside.
Name it#
Every one of those numbers is an address, like a house number for a device, so packets know where to go and where to come back to. An IP address is the number that identifies a device on a network, so data can be sent to it and replies can find their way back.
IP stands for Internet Protocol, the set of rules every device on the internet follows to address and send packets. (Packets are in the What is a network lesson.)
How it works#
Three ideas explain the addresses you saw: how an address is written, why there are two kinds, and why the internet needed a new, longer kind.
1. An IPv4 address is four numbers#
The kind you saw, 192.168.1.7, is an IPv4 address. It is 32 bits long (a bit is a single 0 or 1), written as four numbers separated by dots. Each number is 8 bits, and 8 bits can count from 0 to 255. That gives about 4.3 billion possible addresses in all.
Your phone doesn't pick its own. When it joins the Wi-Fi, the router hands it a free address automatically. (That hand-out has a name, DHCP. You won't need the details yet.)
2. Public addresses and private addresses#
Your router has two sides, and each side has its own address.
- The private address is used only inside your own network. Your router gives these out, and the same private addresses are used again in millions of other homes. They never travel across the internet, because the internet's routers won't pass them on.
- The public address is the one the rest of the internet sees. Your internet provider, your ISP (Jio, Airtel, BSNL), gives it to your router, and it is unique across the whole internet at that moment.
That is why your phone and your friend's can both be 192.168.1.7: each address is private, so it only has to be unique inside its own home.
Three blocks of addresses are set aside for private use. Learn them, because interviews ask which is which:
| Private block | Covers |
|---|---|
| 10.0.0.0/8 | 10.0.0.0 to 10.255.255.255 |
| 172.16.0.0/12 | 172.16.0.0 to 172.31.255.255 |
| 192.168.0.0/16 | 192.168.0.0 to 192.168.255.255 |
(The number after the slash says how many bits at the start are fixed. Note the middle block stops at 172.31: an address like 172.32.0.1 is public. Splitting blocks into smaller ones is called subnetting; you won't need it for this roadmap's next steps.)
How do the private devices reach the internet at all? The router swaps their private address for its one public address on the way out, and swaps it back for the reply. That swap is called NAT, Network Address Translation, and it's what the picture above showed. (The router keeps a small list of who asked for what, so each reply goes back to the right device.)
3. IPv6, because the numbers ran out#
IPv6: 128 bits, not 32.
About 4.3 billion IPv4 addresses sounded like plenty in the 1980s. Today there are more phones than people, plus laptops, TVs, cameras and servers. The free IPv4 addresses ran out years ago, and NAT only stretches them.
So IPv6 was created with much longer addresses: 128 bits instead of 32. It is written as eight groups of four hex digits (0 to 9 and a to f), separated by colons, like 2001:0db8:85a3:0000:0000:8a2e:0370:7334 (runs of zeros may be shortened). That allows about 340 undecillion addresses, enough to give every device its own public address with no sharing at all. Jio's network in India is one of the biggest IPv6 networks in the world, so your phone may already use one.
One special address: your own machine#
127.0.0.1 never leaves your machine.
There is one address that always means "this device itself": 127.0.0.1, called localhost. A message sent to it never leaves your machine. Developers use it all the time: when you run a website on your own laptop, you open it at localhost. In IPv6 the same address is written ::1.
Why it matters#
Every connection starts with an address. When you open a website, your phone needs that site's IP address before a single packet can be sent. (Turning a name like google.com into one is the DNS lesson.) Home routers, office networks, cloud servers and every phone on a mobile network all depend on private addresses, NAT and, more and more, IPv6.
In interviews, the questions on addresses check these:
| Interviews call it | What you saw |
|---|---|
| IP address | a device's number on the network |
| IPv4 | 32 bits, four numbers from 0 to 255 |
| Private IP | used only inside a home or office, reused everywhere |
| Public IP | the one number the internet sees, from your ISP |
| NAT | the router swapping private for public and back |
| IPv6 | 128 bits, made because IPv4 ran out |
| Loopback | 127.0.0.1, localhost, this machine itself |
What to remember#
- An IP address is a device's number on a network, so packets can reach it and replies can come back.
- IPv4 is 32 bits, four numbers from 0 to 255. IPv6 is 128 bits, made because IPv4 ran out.
- Private addresses work only inside a network and are reused in every home: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. That's why two homes can both have 192.168.1.7.
- The public address is the one the internet sees; NAT on the router swaps between them.
- 127.0.0.1, localhost, always means this machine itself.