IP addresses & subnets
Every device on a network has an address, like 192.168.1.50. But the address alone isn't the whole story: the little /24 after it decides which other machines it can talk to directly, and which it has to reach through a router. Once you can read that, half of all "why can't A talk to B?" problems answer themselves.
You will learn
- What an IPv4 address is made of, and what
/24means - Network address, broadcast address and how many hosts fit
- The special ranges: private, loopback, link-local and more
- Answering "is it on my network?", and splitting a network into smaller ones
- Just enough IPv6 to recognise it
An address is 32 bits
An IPv4 address is four numbers from 0 to 255, separated by dots. Each number is one byte (8 bits), so the whole address is 32 ones and zeros:
192 .168 .1 .50
11000000 .10101000 .00000001 .00110010
The address is split into two parts. The network part says which network the device is on, like a street name. The host part says which device on that network, like a house number. The number after the slash (the prefix, or CIDR notation) says how many bits belong to the network part:
192.168.1.50/24 → network 192.168.1 . host 50
# first 24 bits = network, last 8 bits = host
Network, broadcast and hosts
In every network, two addresses are taken: the first one names the network itself, and the last one is the broadcast address, which reaches every device on it at once. Everything in between can be given to a device.
| Prefix | Netmask | Addresses | Usable hosts | Typical use |
|---|---|---|---|---|
/32 | 255.255.255.255 | 1 | 1 | one single machine (firewall rules, routes) |
/30 | 255.255.255.252 | 4 | 2 | a link between two routers |
/28 | 255.255.255.240 | 16 | 14 | a small server network |
/26 | 255.255.255.192 | 64 | 62 | a quarter of a /24 |
/24 | 255.255.255.0 | 256 | 254 | a home or office network |
/16 | 255.255.0.0 | 65,536 | 65,534 | a cloud network (VPC) or a big site |
/8 | 255.0.0.0 | 16.7 million | 16.7 million | the whole 10.x.x.x range |
The quick way to count: a prefix of /n leaves 32 − n host bits, so there are 232 − n addresses. Each step smaller (one bit longer) halves the network: /24 → 256, /25 → 128, /26 → 64.
The netmask is the older way of writing the same thing: ones for the network bits, zeros for the host bits. /24 and 255.255.255.0 mean exactly the same.
Is it on my network?
This is the question your computer asks before sending every packet. If the other address has the same network part, it talks to it directly. If not, it hands the packet to its gateway (a router) and lets the router deal with it. With /24, 192.168.1.80 is a neighbour, but 192.168.2.40 isn't, even though they look almost the same.
On Linux you don't have to work it out by hand. Ask: ip route get ADDRESS. If the answer has via 192.168.1.1, it goes through the router. If it has no via, it's on your network.
Special ranges
Some ranges have a fixed meaning. You'll see these again and again:
| Range | What it is | When you see it |
|---|---|---|
10.0.0.0/8172.16.0.0/12192.168.0.0/16 | Private addresses (RFC 1918) | Homes, offices and cloud networks. Never used on the public internet, so millions of networks can reuse them. |
127.0.0.0/8 | Loopback: this machine itself | 127.0.0.1 / localhost. A service listening only here can't be reached from outside. |
169.254.0.0/16 | Link-local | A machine gave itself one because it couldn't get an address from DHCP. Treat it as an error message. |
100.64.0.0/10 | Shared (carrier-grade NAT) | Inside your internet provider's network. Explained in lesson 2. |
192.0.2.0/24198.51.100.0/24203.0.113.0/24 | Documentation | Examples in books and lessons (like this site). They're never real hosts. |
0.0.0.0 | "Every address" / "no address yet" | 0.0.0.0:22 in ss = listening on every interface; 0.0.0.0/0 = the whole internet (the default route). |
Splitting a network (subnetting)
Say the club gets 10.20.0.0/24 and wants four separate networks: one for servers, one for the lab, one for Wi-Fi and one spare. Borrow 2 more bits for the network part: /24 becomes /26, which gives 22 = 4 networks of 64 addresses each. ipcalc does the maths, but the two families ship different versions with different options:
| Task | Rocky / RHEL | Ubuntu / Debian |
|---|---|---|
| Install | already installed (ipcalc 1.0) | sudo apt install ipcalc (the classic 0.51) |
| Facts about a network | ipcalc 192.168.1.50/24 same on both, different layout | |
| Split into /26s | ipcalc -S 26 10.20.0.0/24 | ipcalc 10.20.0.0/24 /26 |
| Just one value | ipcalc -n (network), -b (broadcast), -m (netmask) | (read it from the full output) |
| What kind of address? | the Address space: line | the end of the Hosts/Net: line (Private Internet) |
Ubuntu's version also prints every address in binary, with a space where the network part ends. It's the best way to see what a prefix does.
One interface, several addresses
A network card can have more than one address. That's how one server can answer for two websites on two addresses, or join two networks on the same cable. sudo ip addr add 192.168.1.51/24 dev enp0s3 adds one until the next reboot. To keep it, save it with NetworkManager or netplan (Linux Sysadmin, lesson 1).
IPv6 in one minute
IPv4 has about 4.3 billion addresses, and they ran out years ago. That's one reason private ranges and NAT exist. IPv6 addresses are 128 bits, written in hexadecimal: 2001:db8:10::10 (:: means "a run of zeros"). A few to recognise:
::1is IPv6 loopback, like127.0.0.1.fe80::…addresses are link-local. Every interface has one automatically.- Networks are almost always
/64: that's 18 quintillion addresses per network, so nobody counts hosts any more. 2001:db8::/32is the documentation range, like192.0.2.0/24.
ip -6 addr shows a machine's IPv6 addresses, and most commands take -6 or -4 to pick one.
Try it: map the club's addresses 🧮
You're on the club server. Find out where it sits, which machines are its neighbours, and plan the new lab network.
Quick check
1. How many devices can you give an address to in 10.20.0.64/26?
✓ 32 − 26 = 6 host bits = 64 addresses, minus the network (10.20.0.64) and broadcast (10.20.0.127) addresses.
2. A laptop shows the address 169.254.33.7. What does that tell you?
✓ Link-local addresses are what a machine uses when DHCP fails. Check the cable, the Wi-Fi or the DHCP server.
3. Your server is 192.168.1.50/24. Can it reach 192.168.2.40 without a router?
✓ With /24 the first three numbers are the network. Different network = through the gateway.