Kestrel Exams kestrel logo KESTREL EXAMSPRACTICE TO PASS
Networking13 min read

IPv4 Addressing: Interfaces, Subnets, Masks and CIDR

Every subnetting question is the same question in disguise: where does the network part of the address stop and the host part start? Once you can see that line in binary, the ranges, masks and host counts all fall out of it.

Practice this topic in the free app →All Networking guides

Chapter 4 · IPv4 addressing
Built from

Kurose and Ross, Computer Networking: A Top-Down Approach, section 4.3 (IPv4 addressing), cross-checked against RFC 791 (Internet Protocol), RFC 950 (Internet Standard Subnetting Procedure) and RFC 4632 (Classless Inter-domain Routing). Every range on this page was recomputed with Python’s ipaddress module.

How to use it

Do every example on paper in binary at least once, even when you can see the answer. The shortcut methods only feel safe after you have watched the bits line up. Then do the practice set without looking back.

The picture: a street name and a house number#

Think of a postal address like “Maple Street, number 14”. The street name gets the letter to the right street. The house number gets it to the right door on that street. Every house on Maple Street shares the street name, and no two share a number.

An IPv4 address works the same way. The first part says which network you are on, like the street. The rest says which device on that network, like the house number. Far-away routers only care about the street. Only the router on your street cares about the house number.

The one twist: an IPv4 address does not have a fixed spot where the street name ends. A small number written after a slash, like /24, tells you where the line falls.

Vocabulary, before anything uses it#

TermWhat it means
InterfaceThe connection point between a device and one link, like a network card’s socket. IP addresses belong to interfaces, not to whole devices.
IPv4 addressA 32-bit number that names one interface. IPv4 means Internet Protocol version 4.
Dotted-decimalThe usual way to write an address: four numbers from 0 to 255, one per byte, separated by dots, like 203.0.113.75.
SubnetA group of interfaces that can reach each other directly, without passing through a router. They share the same network part.
Prefix (network part)The leftmost bits of the address, shared by everyone on the subnet. Its length is the x in a.b.c.d/x.
Host partThe remaining bits on the right. They tell interfaces on the same subnet apart.
Subnet maskThe prefix written as an address: x ones followed by zeros. A /24 prefix has mask 255.255.255.0.
CIDRClassless Inter-Domain Routing: the rule that a prefix may be any length from 0 to 32, written a.b.c.d/x.
Network addressThe first address of a subnet: host part all zeros. It names the subnet itself and is not given to an interface.
Broadcast addressThe last address of a subnet: host part all ones. A datagram sent to it reaches every interface on the subnet.

Addresses belong to interfaces#

A laptop on Wi-Fi usually has one interface in use, so one IPv4 address. A router joins several links, so it has several interfaces, and each one needs its own address. A router with four links has four IP addresses.

An IPv4 address is 32 bits long. That allows 232 = 4,294,967,296 different addresses. To make them readable, we split the 32 bits into four bytes and write each byte as a decimal number from 0 to 255.

Worked example

Write 203.0.113.75 in binary. Convert each byte on its own:
203 = 11001011, 0 = 00000000, 113 = 01110001, 75 = 01001011.
So 203.0.113.75 = 11001011 00000000 01110001 01001011.
Check one: 75 = 64 + 8 + 2 + 1, so the bits for 64, 8, 2 and 1 are on: 01001011.

The bit values in a byte, left to right, are 128, 64, 32, 16, 8, 4, 2, 1. Every conversion is adding up the columns that hold a 1.

Finding the subnets in a network#

Exams often show a drawing of routers and links and ask how many subnets there are. There is a reliable recipe:

  1. Imagine unplugging every interface from its router, so each router stands alone.
  2. What is left is a set of separate “islands” of connected interfaces.
  3. Each island is one subnet. Count them.

Two things trip people up. A LAN (local area network, such as one office’s wired network) with many hosts behind one switch is one island, because a switch is not a router. And a cable joining two routers directly is an island too: a subnet with just two interfaces in it.

Worked example

Router R1 serves two office LANs. Router R2 serves two lab LANs. R1 and R2 are joined by one cable. Unplug the routers and you get four LAN islands plus the island made by the R1-to-R2 cable. That is 5 subnets. R1 has three interfaces (two LANs and the cable), so it needs three addresses, each from a different subnet.

Reading a.b.c.d/x: prefix, mask and host count#

The x after the slash is the prefix length: how many bits from the left are the network part. The other 32 − x bits are the host part. Write h for that number of host bits.

addresses in the block = 2h     usable host addresses = 2h − 2

You subtract 2 because the all-zeros host part is the network address and the all-ones host part is the broadcast address. Neither goes on an interface.

PrefixSubnet maskHost bits hAddressesUsable hosts
/20255.255.240.0124,0964,094
/23255.255.254.09512510
/24255.255.255.08256254
/25255.255.255.1287128126
/26255.255.255.19266462
/27255.255.255.22453230
/28255.255.255.24041614
/30255.255.255.252242
Worked example

An interface has address 203.0.113.75/26. Find its subnet.
The prefix is 26 bits, so the first three bytes (24 bits) are all network, plus 2 bits of the last byte. The mask is 11111111 11111111 11111111 11000000 = 255.255.255.192.
Last byte: 75 = 01|001011. Keep the 2 network bits (01) and set the 6 host bits to zeros: 01000000 = 64. Set them to ones: 01111111 = 127.
So the network address is 203.0.113.64, the broadcast address is 203.0.113.127, and the usable range is 203.0.113.65 to 203.0.113.126: 26 − 2 = 62 hosts.

Do not confuse these
The network address and the subnet mask are different things. 203.0.113.64 is the network address: the first address in this particular block. 255.255.255.192 is the mask: it only says how long the prefix is, and it is the same for every /26 anywhere.

One exception: on a cable joining exactly two routers, RFC 3021 allows a /31 (2 addresses) with no network or broadcast address. Use the “minus 2” rule unless a question raises /31 on purpose.

Designing subnets from one block#

An organization splits its one block among its departments. Every subnet must start on a multiple of its own size.

Equal-size subnets

Borrowing n bits from the host part gives 2n subnets of equal size.

Worked example

Split 192.168.40.0/24 into four equal subnets. Four is 22, so borrow 2 bits: each subnet is a /26 of 64 addresses.

SubnetUsable rangeBroadcast
192.168.40.0/26192.168.40.1 to .62192.168.40.63
192.168.40.64/26192.168.40.65 to .126192.168.40.127
192.168.40.128/26192.168.40.129 to .190192.168.40.191
192.168.40.192/26192.168.40.193 to .254192.168.40.255

Variable-size subnets

Real departments are not the same size. Giving each one a block that fits is called VLSM, variable-length subnet masking. The method:

  1. For each group, add 2 to the hosts needed and round up to a power of two. That is its block size.
  2. Sort the groups from largest block to smallest.
  3. Hand out blocks from the start of the range in that order. Big blocks first keeps every block lined up on a multiple of its size.
Worked example

A school owns 198.51.100.0/24. It needs 100 hosts for labs, 50 for offices, 20 for the library, and a router-to-router link with 2 interfaces.
Labs: 100 + 2 = 102, round up to 128 = 27, so a /25. Offices: 52 → 64, a /26. Library: 22 → 32, a /27. Link: 4 → 4, a /30.

GroupBlockUsable rangeBroadcastUsable hosts
Labs (100)198.51.100.0/25.1 to .126.127126
Offices (50)198.51.100.128/26.129 to .190.19162
Library (20)198.51.100.192/27.193 to .222.22330
Link (2)198.51.100.224/30.225 to .226.2272

That leaves 198.51.100.228 to 198.51.100.255, 28 addresses, spare for later.

Do not confuse these
“Needs 30 hosts” does not mean a block of 30. Add the network and broadcast addresses first (32), then round up to a power of two (32, a /27). For 31 hosts you need 33, which rounds up to 64, a /26.

Classful addressing, as history#

Before CIDR, the prefix length was fixed by the first few bits of the address. This was classful addressing, and you may still see it in older material.

ClassFirst bitsFirst bytePrefixUsable hosts per network
A00 to 127/816,777,214
B10128 to 191/1665,534
C110192 to 223/24254
D1110224 to 239multicast, no hostsn/a
E1111240 to 255reservedn/a

The sizes jumped too far: a class C was too small for most organizations and a class B far too big. CIDR fixed this by letting the prefix be any length. People still say “class C” loosely to mean “a /24”, but routers ignore classes completely.

One sentence to carry into the exam

In a.b.c.d/x the first x bits name the subnet and the other 32 − x bits name the interface, so the block holds 232−x addresses, of which all but the all-zeros network address and the all-ones broadcast address can go on interfaces.

Practice#

Work in binary for the first few, even where you could guess. Write 128 64 32 16 8 4 2 1 across the top of your page.

  1. Write 172.29.6.130 in binary.
  2. Write 11000110 00110011 01100100 00001010 in dotted-decimal.
  3. Router R1 connects three LANs and has a direct cable to R2 and another to R3. R2 and R3 each connect one LAN and are not cabled to each other. How many subnets are there?
  4. A host has address 10.14.77.200/20. Give the subnet mask, network address, broadcast address, usable range and number of usable hosts.
  5. A department needs 500 host addresses. What is the longest prefix (smallest block) that fits, and how many usable hosts does it give?
  6. 192.168.40.0/24 is split into equal /27 subnets. How many subnets are there, how many usable hosts does each have, and what is the usable range of the third one?
  7. Are 192.0.2.61 and 192.0.2.66 on the same subnet if the prefix is /25? What if it is /26?
  8. An organization needs 2,000 host addresses. Compare what classful addressing could give it with what CIDR can give it.

Solutions#

Best study method

Find the first line where your working split from the solution, and redo the problem from that line. Do not just read the answer and nod.

  1. 10101100 00011101 00000110 10000010. 172 = 128 + 32 + 8 + 4; 29 = 16 + 8 + 4 + 1; 6 = 4 + 2; 130 = 128 + 2.
  2. 198.51.100.10. 11000110 = 128 + 64 + 4 + 2 = 198; 00110011 = 32 + 16 + 2 + 1 = 51; 01100100 = 64 + 32 + 4 = 100; 00001010 = 8 + 2 = 10.
  3. 7 subnets. Unplug every router interface: the LAN islands are 3 (on R1) + 1 (on R2) + 1 (on R3) = 5, and the two router-to-router cables are 2 more.
  4. Mask 255.255.240.0; network 10.14.64.0; broadcast 10.14.79.255; usable 10.14.64.1 to 10.14.79.254; 4,094 hosts. A /20 keeps 4 bits of the third byte. 77 = 0100|1101; zeroing the low 4 bits gives 01000000 = 64, setting them to ones gives 01001111 = 79. Host bits: 32 − 20 = 12, so 212 − 2 = 4,094.
  5. A /23, with 510 usable hosts. 500 + 2 = 502 addresses needed. The next power of two is 512 = 29, so 9 host bits and a prefix of 32 − 9 = 23. 512 − 2 = 510.
  6. 8 subnets, 30 usable hosts each; the third is 192.168.40.65 to 192.168.40.94. A /27 borrows 3 bits from the /24, so 23 = 8 subnets of 32 addresses. They start at .0, .32, .64, ... The third is 192.168.40.64/27: network .64, broadcast .95, usable .65 to .94.
  7. Same subnet under /25; different subnets under /26. Under /25 the blocks are .0 to .127 and .128 to .255, and both addresses are in the first. Under /26 the blocks are .0 to .63 and .64 to .127, so 61 and 66 fall on either side of the boundary at 64.
  8. Classful: a class B, wasting 63,534 addresses. CIDR: a /21 with 2,046 usable hosts. (The alternative was eight separate class C networks, 2,032 usable hosts, but that means eight routing-table entries instead of one.) A class C has only 254 usable hosts, too few. A class B has 65,534, and 65,534 − 2,000 = 63,534 go unused. With CIDR, 2,002 rounds up to 2,048 = 211, a /21, wasting only 46.

Test-readiness checklist#

  • ☐  I can explain why a router has one IP address per interface.
  • ☐  I can convert between dotted-decimal and binary without a calculator.
  • ☐  I can count the subnets in a drawing by unplugging the router interfaces.
  • ☐  I can turn a /x into a subnet mask, and a mask back into a /x.
  • ☐  I can find the network address, broadcast address and usable range for any a.b.c.d/x.
  • ☐  I can split a block into equal subnets, and into variable-size subnets, largest first.
  • ☐  I can say what classful addressing was and why CIDR replaced it.
One last rule

When a subnetting answer looks odd, check that the network address is a multiple of the block size in the byte where the prefix ends. A /26 must start at 0, 64, 128 or 192. If yours starts at 70, the mistake is upstream.

Frequently asked questions#

What does the /24 in 192.168.1.0/24 mean?

It is the prefix length. The first 24 bits of the address are the network part shared by every interface on that subnet, and the remaining 8 bits identify individual interfaces. It says the same thing as the subnet mask 255.255.255.0.

How many usable hosts are in a subnet?

A prefix of length x leaves 32 minus x host bits, so the block holds 2 to the power of (32 minus x) addresses. Two of them, the network address and the broadcast address, cannot go on interfaces, so the usable count is that number minus 2. A /26 has 64 addresses and 62 usable hosts.

Why does a router have more than one IP address?

IP addresses belong to interfaces, not to devices. A router connects several links and has one interface on each, so each interface gets its own address from the subnet on that link.

What is the difference between a subnet mask and a network address?

The subnet mask only describes the prefix length, written as ones followed by zeros, such as 255.255.255.192 for a /26. The network address is the first address of one particular block, such as 203.0.113.64 for the /26 that contains 203.0.113.75.

Is classful addressing still used?

No. Routers have used CIDR, where a prefix can be any length, since the 1990s. Class names survive only as loose shorthand.

Suggest a change

Something here not clear? A topic you wish we covered? Tell us. We read every message, and a request is the fastest way to get a guide written.

Test yourself on this topic

The free networking practice app has 10 questions on this guide and 500 across the whole course, each with an explanation for every answer. Offline, no ads, no account.

Practise this topic →