Skip to content
BoKSA

12 – IP Addressing and Subnetting

12 – IP Addressing and Subnetting

Course: ICT Basic course · Level: introductory, lots of practice Book: Kurose & Ross, 9th ed., chapter 4.3 (IPv4 addressing, CIDR)

Learning goals

After this article you can:

  • convert between binary and decimal numbers (8 bits);
  • split an IP address into network ID and host ID using a subnet mask or prefix length (/x);
  • calculate the network address, broadcast address, first/last usable host and number of hosts of a subnet;
  • divide an address block into subnets of suitable size (including VLSM);
  • explain why subnetting is useful, and apply the same idea to IPv6.

1. Why subnets?

A subnet is a part of a network in which devices can reach each other directly, without a router. Routers connect subnets.

Reasons to divide a network into subnets:

  • Limit broadcast traffic: broadcasts (ARP, DHCP) only reach the own subnet.
  • Organisation and security: separate subnets for departments, servers, guests, IoT, management. A firewall/router between them can control traffic.
  • Efficient use of addresses: IPv4 addresses are scarce; give each part exactly what it needs.

How many subnets? Remove all routers from the picture: every remaining "island" of connected interfaces is one subnet. Point-to-point links between routers are also subnets!


2. Binary numbers

An IPv4 address is 32 bits, written as 4 octets (bytes) in decimal: 192.168.1.10.

Each bit in an octet has a value:

Bit 7 6 5 4 3 2 1 0
Value 128 64 32 16 8 4 2 1

Binary → decimal: add the values where there's a 1. 01011011 = 64 + 16 + 8 + 2 + 1 = 91 11010101 = 128 + 64 + 16 + 4 + 1 = 213

Decimal → binary: subtract the largest value that fits, from left to right. 172 = 128 (rest 44) + 32 (rest 12) + 8 (rest 4) + 4 → 10101100

Highest value in one octet: 11111111 = 255. So the highest IPv4 address is 255.255.255.255.

Values to remember (subnet mask octets)

Binary Decimal Binary Decimal
10000000 128 11111000 248
11000000 192 11111100 252
11100000 224 11111110 254
11110000 240 11111111 255

3. Network ID, host ID and subnet mask

Every IP address has two parts:

1
2
3
4
5
    192.168.1.10 /24
   ┌─────────────┬─────┐
   │ network ID  │host │
   │ 192.168.1   │ 10  │
   └─────────────┴─────┘
  • Network ID: identifies the subnet. The same for all devices in that subnet.
  • Host ID: identifies the interface within the subnet.

The subnet mask tells where the boundary is: 1-bits = network part, 0-bits = host part.

1
2
3
4
IP address   192.168.1.10    11000000.10101000.00000001.00001010
Subnet mask  255.255.255.0   11111111.11111111.11111111.00000000
             ─────────────── bitwise AND ───────────────────────
Network ID   192.168.1.0     11000000.10101000.00000001.00000000

Classful addressing (legacy) vs. CIDR

Legacy: in the early Internet, addresses were divided into fixed classes: A (/8, first octet 1–126), B (/16, 128–191), C (/24, 192–223). This wasted lots of addresses (an organisation that needed 300 addresses got a class B with 65,534). Classes have been obsolete since 1993. You still hear the terms ("a class C network") as an informal name for a /24.

CIDR (Classless Inter-Domain Routing): the boundary can be anywhere. We write the number of network bits after a slash: /x (prefix length).

192.168.1.0/25 → the first 25 bits are 1: 11111111.11111111.11111111.10000000 = 255.255.255.128


4. Calculating a subnet – the method

For any prefix /x:

Step Formula
Host bits h = 32 − x
Total addresses in the subnet 2ʰ (also: 256 − last mask octet, if the boundary is in the last octet)
Usable host addresses 2ʰ − 2 (the first is the network address, the last is the broadcast address)
Network address IP AND mask (all host bits 0)
Broadcast address all host bits 1 = network address + 2ʰ − 1
First usable host network address + 1
Last usable host broadcast address − 1

Exception: a /31 (2 addresses) may be used for point-to-point links between routers (RFC 3021), and a /32 is a single host route.

Quick table

Prefix Mask Addresses Usable hosts Block size (last octet)
/24 255.255.255.0 256 254 256
/25 255.255.255.128 128 126 128
/26 255.255.255.192 64 62 64
/27 255.255.255.224 32 30 32
/28 255.255.255.240 16 14 16
/29 255.255.255.248 8 6 8
/30 255.255.255.252 4 2 4
/23 255.255.254.0 512 510 (2 in third octet)
/22 255.255.252.0 1024 1022 (4 in third octet)
/16 255.255.0.0 65,536 65,534

Worked example 1

Given: 192.168.1.77/27. Find the network, broadcast, host range and number of hosts.

  1. /27 → mask 255.255.255.224 → block size 256 − 224 = 32.
  2. Subnets in the last octet start at 0, 32, 64, 96, 128… → 77 lies in the block starting at 64.
  3. Network address: 192.168.1.64
  4. Broadcast: 64 + 32 − 1 = 192.168.1.95
  5. Usable hosts: 192.168.1.65 – 192.168.1.94 → 30 hosts (2⁵ − 2).

Worked example 2

Given: 173.44.6.2 with mask 255.255.0.0 (/16). Network ID: 173.44.0.0, host ID: 6.2, broadcast 173.44.255.255, 65,534 hosts.

Worked example 3 – the boundary in the third octet

Given: 10.20.37.200/22. /22 → mask 255.255.252.0 → block size in third octet = 4 → blocks 0, 4, …, 32, 36, 40 → 37 lies in 36. Network 10.20.36.0, broadcast 10.20.39.255, hosts 10.20.36.1 – 10.20.39.254 (1,022 hosts).


5. Designing subnets

5.1 Equal-size subnets

Task: divide 192.168.10.0/24 into 4 equal subnets. 4 = 2² → borrow 2 bits → /26 (64 addresses, 62 hosts each):

Subnet Network Host range Broadcast
1 192.168.10.0/26 .1 – .62 .63
2 192.168.10.64/26 .65 – .126 .127
3 192.168.10.128/26 .129 – .190 .191
4 192.168.10.192/26 .193 – .254 .255

Rule: borrowing n bits gives 2ⁿ subnets.

5.2 VLSM – Variable Length Subnet Masks

Usually the subnets have different sizes. With VLSM, each gets its own prefix. Method: sort the subnets from largest to smallest, and assign them one after the other.

Task: 192.168.1.0/24 for: Students 100 hosts, Staff 50, Servers 20, Management 10, plus 2 router links (2 hosts each).

Subnet Hosts needed Prefix (usable hosts) Network Range Broadcast
Students 100 /25 (126) 192.168.1.0/25 .1 – .126 .127
Staff 50 /26 (62) 192.168.1.128/26 .129 – .190 .191
Servers 20 /27 (30) 192.168.1.192/27 .193 – .222 .223
Management 10 /28 (14) 192.168.1.224/28 .225 – .238 .239
Link R1–R2 2 /30 (2) 192.168.1.240/30 .241 – .242 .243
Link R2–R3 2 /30 (2) 192.168.1.244/30 .245 – .246 .247
free 192.168.1.248/29

Don't forget: every subnet also needs an address for the router interface (gateway), so count it as a host.

5.3 Route aggregation (supernetting)

The opposite of subnetting: an ISP that owns 200.23.16.0/23, 200.23.18.0/23, … can announce all of them as one prefix, 200.23.16.0/20. This keeps Internet routing tables small.


6. IPv6 subnetting (short)

IPv6 subnetting is easier: you don't count hosts, because every LAN gets a /64 (2⁶⁴ addresses).

  • An ISP typically gives a home a /56 (256 subnets) or /48 (65,536 subnets); a company/site gets a /48.
  • You simply number your subnets in the 4th group: 2001:db8:abcd:0001::/64, 2001:db8:abcd:0002::/64, …
  • No broadcast address, no "−2".

7. Exercises

  1. Convert to decimal: 10101010, 11100000, 00111111.
  2. Convert to binary: 200, 77, 255.
  3. For 172.16.45.130/26: network, broadcast, first and last host, number of hosts.
  4. How many hosts can be assigned an address in 192.168.1.0/26? And in /29?
  5. What is the mask for /20 in dotted decimal?
  6. Are 192.168.5.66/27 and 192.168.5.97/27 in the same subnet?
  7. Divide 10.0.0.0/24 with VLSM over: 60 hosts, 28 hosts, 12 hosts, 2 router links.
  8. A router has 8 interfaces. How many IP addresses does it have?
Answers 1. 170, 224, 63 2. `11001000`, `01001101`, `11111111` 3. Block 64 → network 172.16.45.128, broadcast .191, hosts .129 – .190, 62 hosts 4. /26: 64 − 2 = **62**; /29: 8 − 2 = **6** 5. 255.255.240.0 6. No: block size 32 → .66 is in .64–.95, .97 is in .96–.127 7. 60 → 10.0.0.0/26 (.1–.62); 28 → 10.0.0.64/27 (.65–.94); 12 → 10.0.0.96/28 (.97–.110); links → 10.0.0.112/30 and 10.0.0.116/30 8. 8 – one per interface (each in a different subnet)

More practice: https://subnettingpractice.com/

Check your understanding

  1. Why are the first and last address of a subnet not usable for hosts?
  2. What is the difference between classful addressing and CIDR?
  3. What does /27 mean, and how many usable addresses does it give?
  4. Why do you assign the largest subnets first with VLSM?
  5. Why don't you need to count hosts when subnetting IPv6?

References

Book and course material

  • Kurose & Ross, 9th ed., chapter 4.3 (IPv4 addressing)
  • HvA DLO – subnetting material (original course)

Videos

Tools


Cyber Security

Why is this important for cyber security?

  • Subnets are the basis of network segmentation. In a "flat" network (everything in one big subnet) an attacker who infects one PC can directly reach every server, camera and printer: lateral movement. Many ransomware attacks spread exactly like this.
  • Firewall rules work with subnets. Rules like "allow 10.10.20.0/24 (staff) to 10.10.50.0/27 (servers) on port 443" only make sense with a clear address plan. A wrong mask can accidentally allow far more than intended (e.g. /16 instead of /24 opens 65,536 instead of 256 addresses).
  • Broadcast domains = attack domains. ARP spoofing and rogue DHCP only work within one broadcast domain. Smaller subnets limit the impact.
  • Knowing the address plan helps attackers. That's why internal address plans and network diagrams are confidential.

What can you do to make it safe?

  • Segment by function and trust level: e.g. separate subnets/VLANs for users, servers, management, guests, IoT/OT and backups, with a firewall between them (zone-based design).
  • Least privilege between subnets: default deny; only allow the traffic that is really needed.
  • Use a management network: the admin interfaces of switches, routers and servers (SSH, iLO/iDRAC) belong in a separate, protected subnet.
  • Document the address plan (IPAM) and keep it up to date, so you can quickly identify unknown devices during an incident.
  • Plan IPv6 segmentation too (and make firewall rules for it).
  • Go further: micro-segmentation and zero trust (article 18) apply the same principle down to individual workloads.

Extra references