Loading
0x30Lesson 4 of 15

Read IPv4 addresses and prefixes

Use a network prefix to identify addresses in the same subnet.

30 min 7-question quiz
By the end of this lesson you can
  • Split an IPv4 address into network and host bits.
  • Calculate a network address, broadcast address and host count from a CIDR prefix.
  • Decide whether two addresses are on the same subnet.

MAC addresses work on one network, but they can't scale to the whole Internet: no router could remember billions of unrelated addresses. IP addresses solve this the way street addresses do. They're hierarchical, so a router far away only needs to know the general direction of a whole network, not of each device.

Network bits and host bits

An IPv4 address is 32 bits, written as four decimal octets. CIDR notation adds a prefix length such as /24, which says how many leading bits name the network. The rest name a host on that network.

19211000000168101010004000001002700011011Network part: 24 bitsHost part: 8 bitsLike the street: routers only care about thisLike the house numberSame network bits means same subnet, so no router is needed
192.168.4.27/24: the prefix says 24 bits name the network, leaving 8 to name a host on it.

A worked example: 192.168.4.77/26

Prefixes that fall on a dot, such as /24, can be read by eye. The real skill is handling ones that don't. Here's the method, step by step:

  1. /26 keeps all of the first three octets (24 bits) plus 2 bits of the last octet.
  2. That leaves 6 host bits, so each block has 2⁶ = 64 addresses.
  3. Blocks in the last octet start at 0, 64, 128 and 192.
  4. 77 falls in the block starting at 64, so the network is 192.168.4.64.
  5. The block ends at 127, so the broadcast address is 192.168.4.127.
  6. Two addresses are reserved (network and broadcast), leaving 62 usable hosts.

Try it

Up to 15 XP

Move the line between network and host

Start at /24 and drag the prefix to /26, watching the blue bits and the block on the ruler. Then try /16, /30 and /32. Type your own address too. What happens to the number of hosts each time you add one bit?

When you're ready, solve the challenges by hand. The calculator above is there to check your reasoning, but try not to use it first.

24 network bits8 host bits

Network address
192.168.4.0/24
Subnet mask
255.255.255.0
Broadcast address
192.168.4.255
Host range
192.168.4.1 – 192.168.4.254
Usable hosts
254

How the prefix divides octet 4. The blue block holds this address, and the red line marks its value.

02550–255

Solve it by hand

Score 0/0

What is the network address of 192.168.4.77/26?

Why it matters: local or not?

Before sending anything, a host compares the destination with its own network. If the network bits match, the destination is local and can be reached directly. If they don't, the packet goes to the default gateway, a router on the local network. A wrong prefix is a classic cause of “I can reach some machines but not others”.

The mask does this with a bitwise AND, which keeps the network bits and zeroes the rest:

192.168.4.77/26
address   11000000.10101000.00000100.01001101   192.168.4.77
mask      11111111.11111111.11111111.11000000   255.255.255.192
AND       11000000.10101000.00000100.01000000   192.168.4.64

Plan a real network

This is the job subnetting exists for. You're given one block of addresses, and you have to give each team its own subnet. Giving everyone a big subnet wastes the block, and too small a subnet runs out of addresses.

Try it

Up to 15 XP

Divide a /24 between four teams

Your office has been given 10.20.0.0/24. Choose a prefix for each team: the smallest subnet that holds its hosts. Remember that each subnet loses two addresses.

The largest subnets are placed first, which keeps each one on a clean boundary. How much room is left for the next team?

  • Just right: 126 usable
  • Bigger than it needs: 126 usable
  • Bigger than it needs: 126 usable
  • Bigger than it needs: 126 usable
How the subnets fill 10.20.0.0/24
Addresses used
512 / 256
Addresses left
0

That needs 256 more addresses than the block has. Make some subnets smaller.

Try it

Up to 15 XP

Read an interface's settings

Real machines show their address and prefix together. Click the line that answers the question.

Round 1 of 2: Find the addressScore 0/0

Which line tells you this machine's IPv4 address and subnet size?

$ ip addr show eth0

Key takeaways

  • A prefix splits an address into network bits and host bits.

  • Each host bit you remove halves the block, and each one you add doubles it.

  • Hosts compare network bits to choose between direct delivery and the default gateway.

Lesson quiz

7 questions · pass with 5 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…