Every subnet loses two addresses
Inside a block, two addresses are not assignable to a host.
- The network address has all host bits set to 0. It names the subnet itself, and it is what appears in a routing table. - The broadcast address has all host bits set to 1. A packet sent there is delivered to every host in the subnet.
Everything strictly between them is a usable host address. That is the definition, and the arithmetic to find those two boundaries is two bitwise operations.
network = address AND mask
broadcast = address OR (NOT mask)AND gives 1 only when both bits are 1, so ANDing with the mask keeps the
network bits and zeroes the host bits. NOT mask is the mask flipped, which is
1 exactly over the host bits, so ORing sets them all to 1.
Worked out bit by bit
Given 192.168.10.130/26, find the network, the broadcast, and the usable range.
Step 1, write the mask. /26 means 26 ones then 6 zeros.
255.255.255.192 11111111 11111111 11111111 11000000
Step 2, only the last octet is interesting, because the first three octets
of the mask are all 1s and copy straight through. Write 130 in binary:
128 + 2, so 10000010.
Step 3, AND for the network address.
10000010 (130) & 11000000 (mask, last octet 192) -------- 10000000 = 128 network = 192.168.10.128/26
Step 4, OR with the inverted mask for the broadcast. NOT 11000000 is 00111111.
10000010 (130) | 00111111 (inverted mask) -------- 10111111 = 128 + 32 + 16 + 8 + 4 + 2 + 1 = 191 broadcast = 192.168.10.191
Step 5, read off the answers.
| Item | Value |
|---|---|
| Network address | 192.168.10.128 |
| First usable host | 192.168.10.129 |
| Last usable host | 192.168.10.190 |
| Broadcast address | 192.168.10.191 |
| Usable hosts | 2⁶ − 2 = 62 |
A shortcut worth learning after you can do the long version. The block size of a /26 is 256 − 192 = 64, so /26 networks in this octet start at 0, 64, 128, and 192. 130 falls in the block starting at 128, whose last address is 128 + 64 − 1 = 191. Same answers, no binary. Do it in binary until the shortcut feels obvious, not before.
The two exceptions
The minus two rule has exactly two exceptions, both for links rather than subnets full of hosts.
- A /32 is one single address with zero host bits. It means "this exact host", and it is what a routing table shows for a host route and what a loopback interface uses. - A /31 holds two addresses and, by RFC 3021, both are usable on a point to point link. There is no need for a broadcast address when a link has exactly two ends, because sending to the other end is the only option.
A /30 is the older way to do a point to point link, giving 4 addresses of which 2 are usable, so it wastes half. You will see both in real routing configurations.
Ranges that do not mean what you expect
Some blocks are reserved and behave specially. Knowing this table saves hours, because seeing one of these addresses immediately tells you what is happening.
| Range | Name | What it means |
|---|---|---|
| 10.0.0.0/8 | private, RFC 1918 | not routable on the internet |
| 172.16.0.0/12 | private, RFC 1918 | covers 172.16.0.0 to 172.31.255.255 |
| 192.168.0.0/16 | private, RFC 1918 | the usual home network range |
| 127.0.0.0/8 | loopback | never leaves the host, 127.0.0.1 is localhost |
| 169.254.0.0/16 | link local | self assigned when DHCP fails |
| 100.64.0.0/10 | carrier grade NAT | your ISP's internal space, RFC 6598 |
| 224.0.0.0/4 | multicast | group delivery, not one host |
| 255.255.255.255 | limited broadcast | this link only, used by DHCP |
| 0.0.0.0 | unspecified | "no address yet", or "any" when listening |
| 0.0.0.0/0 | default route | matches everything, see Lesson 5-1 |
| 192.0.2.0/24 | documentation | safe to use in examples, RFC 5737 |
Two of these are diagnoses on their own. A host holding a 169.254.x.x address did not get a DHCP answer, so the DHCP server or the link is broken, and no amount of application debugging will help. A 100.64.x.x address on your router's outside interface means you are behind carrier grade NAT, so inbound connections from the internet cannot reach you at all, which Lesson 6-2 explains.
Note that RFC 1918 addresses are not secure, they are just unroutable. Anyone can use 10.0.0.0/8 internally, which is why merging two companies that both chose 10.0.0.0/8 is a genuinely painful project.
Reading it off a real machine
ip -4 addr show dev eth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 inet 192.168.10.130/26 brd 192.168.10.191 scope global eth0
Everything from the worked example is in that one line. The address is
192.168.10.130, the prefix is /26, and the kernel has already computed
brd 192.168.10.191 as the broadcast. mtu 1500 is the number from Lesson 3-3.
One last habit that pays off. When two hosts cannot talk on what looks like the same network, AND both addresses with the mask and compare the results. If the network addresses differ, they are on different subnets and need a router, no matter how similar the addresses look. A host at 192.168.10.130/26 and a host at 192.168.10.70/26 are in different subnets, because 70 lands in the 64 block and 130 lands in the 128 block. Work a few of these out on paper until the answer comes without the arithmetic.