Computer Networks / Practical class / Practical class 3
Practical class · Computer Networks

Subnetting – dividing networks into smaller segments

The university received one 192.168.10.0/24 network from the provider, but the dean’s office, the computer lab, the library and the guest Wi-Fi must not get mixed up in it. The solution is subnetting: splitting one large network into several smaller segments. This is the 1st class on subnetting: you will learn to calculate the mask, prefix, AND operation, the “magic number” and equal-sized subnets by hand, then check the result with Python. In the 2nd class (practical 4) this knowledge is used for VLSM, a real project and troubleshooting.

:ik-kitob: Practical class 3 ⏱ 2 academic hours (80 minutes) 🚇 Packet simulators ⚡ One network — many segments
03

Lesson goals and plan

By the end of the lesson you will…

  • You can convert between network mask and prefix (/n) notations
  • You can find a network address by hand by applying the AND operation to an IP address and a mask
  • You can quickly calculate the network, broadcast and host range using the “magic number” (block size) method
  • You can determine the required prefix from a host requirement, and the number of borrowed bits from a subnet requirement
  • You can split a network into equal-sized subnets and build a complete subnet table
  • You can justify with calculations whether two addresses are in the same subnet or not

Plan (according to the syllabus)

  1. Subnetting – dividing networks into smaller segments

Put the calculator aside in this class! Calculate by hand first, then check with the Python task or the widget. What will help you most in the exam and in real work is the magic number: 256 − the “interesting” octet of the mask. In practical 4 we build VLSM on exactly this skill.

Why is one big network bad?

Suppose 500 phones in a dormitory, the accounting computers in the dean’s office and the library printers are all on one network: every broadcast message is heard by everyone (the network is “noisy”), one student’s virus easily reaches accounting, and looking for a fault turns into looking for a needle in a haystack. The metro is not one giant line either — it is split into several lines. Today we will learn to split a network into “lines” in the same way.

Key terms

Theory reminder

In practical 1 we looked at classful addresses: class C is /24, i.e. 254 hosts. Subnetting “moves” the rigid boundary of the class: we take a few bits from the host part and add them to the network part. The more bits we take, the more subnets we get, but the smaller they are.

Table 3.1. Masks for the last octet (the main cheat sheet)
PrefixMaskLast octet (binary)Magic numberSubnets within /24Hosts/subnet
/24255.255.255.0000000002561254
/25255.255.255.128100000001282126
/26255.255.255.1921100000064462
/27255.255.255.2241110000032830
/28255.255.255.24011110000161614
/29255.255.255.248111110008326
/30255.255.255.252111111004642
1

Number of subnets

2s, where s is the number of borrowed bits.

2

Number of hosts

2h − 2, where h is the number of remaining host bits (h = 32 − prefix).

3

Block size

256 − mask octet — subnets start at this step.

Python: bitwise operations and ipaddressip   = 0xC0A80A4D                     # 192.168.10.77 as a single number
mask = (0xFFFFFFFF << (32 - 26)) & 0xFFFFFFFF   # /26 mask
net  = ip & mask                        # AND → network address
bc   = net | (~mask & 0xFFFFFFFF)         # OR host bits → broadcast
import ipaddress
n = ipaddress.ip_network("192.168.10.77/26", strict=False)
list(ipaddress.ip_network("192.168.10.0/24").subnets(new_prefix=26))

Subnetting – dividing networks into smaller segments

Session 1 · basics

This is the first of two classes on subnetting: the mask, AND, the magic number and splitting into equal-sized (FLSM) subnets — all by hand. Session 2 (practical 4) covers subnets of different sizes (VLSM), the university project, point-to-point links, the router console and troubleshooting.

Sample task 1. Which subnet is 192.168.10.77/26 in? (the AND method)

  1. Convert the prefix to a mask

    /26 → 26 ones: 11111111.11111111.11111111.11000000 = 255.255.255.192.

  2. Convert only the “interesting” octet to binary

    In the first three octets the mask is 255 — they do not change (192.168.10). Last octet: 77 = 01001101, mask 192 = 11000000.

  3. The AND operation

    01001101 AND 11000000 = 01000000 = 64. Network address: 192.168.10.64.

  4. Broadcast and hosts

    Fill the host bits (the last 6 bits) with 1s: 01111111 = 127 → broadcast 192.168.10.127. Hosts: from .65 to .126, in total 26 − 2 = 62.

AND — bit by bitIP      192.168.10.77   → ...00001010.01001101
Mask    255.255.255.192 → ...11111111.11000000
                          ─────────────────────
Network 192.168.10.64   → ...00001010.01000000    # network bits kept, host bits 0

Sample task 2. The same — with the magic number (in 10 seconds)

  1. Magic number

    The mask’s “interesting” octet is 192 → 256 − 192 = 64. Subnets: .0, .64, .128, .192.

  2. Which block does the IP fall into?

    Divide 77 by 64: 77 // 64 = 1 → 1 × 64 = 64. Network: 192.168.10.64.

  3. Subtract one from the next block

    The next subnet is .128 → broadcast = 128 − 1 = .127. Hosts .65 – .126.

Formula

Network octet = (IP octet // block) × block. Broadcast octet = network octet + block − 1. These two lines are 80 percent of all subnetting.

Sample task 3. Splitting 192.168.10.0/24 into 4 equal subnets

  1. How many bits are borrowed?

    2s ≥ 4 → s = 2. New prefix: 24 + 2 = /26 (255.255.255.192).

  2. Are there enough hosts?

    Host bits 32 − 26 = 6 → 26 − 2 = 62 hosts in each subnet.

  3. A table using the block size

    We write it out with a step of 256 − 192 = 64:

Table 3.2. 192.168.10.0/24 → 4 × /26
№NetworkFirst hostLast hostBroadcastAssigned to
1192.168.10.0/26.1.62.63Dean’s office
2192.168.10.64/26.65.126.127Computer lab
3192.168.10.128/26.129.190.191Library
4192.168.10.192/26.193.254.255Guest Wi-Fi

Lab: the subnet “X-ray” and the magic-number trainer

Change the IP and the prefix: the widget shows the address, mask and AND result in bits (red — network bits, blue — host bits), and below it draws how the “interesting” octet is split into subnets, like a metro line. The Trainer button asks a random question — enter the network and broadcast address yourself.

:ik-kalkulyator: Subnet X-ray

IP:Prefix: /26
Mask
Network
Broadcast
Number of hosts
First host
Last host
Magic number (block)
Interesting octet

Question: — what are the network and broadcast addresses?

Finding the prefix from host and subnet requirements

If “at least H hosts in each subnet”

Find the smallest h: 2h − 2 ≥ H. Prefix = 32 − h.

For example, H = 50: 25 − 2 = 30 (not enough), 26 − 2 = 62 ✓ → h = 6 → /26.

If “at least N subnets”

Find the smallest s: 2s ≥ N. Prefix = old prefix + s.

For example, from /24 with N = 5: 22 = 4 (not enough), 23 = 8 ✓ → /27, 8 subnets (3 of them spare).

Independent tasks

7 tasks. Try to write 1–4 without ipaddress (using bitwise operations or arithmetic) — then you will understand what happens “inside the machine”. In 5–7, feel free to use the module.

Common mistakes

ErrorConsequenceCorrect answer
Taking the number of hosts to be 2hthe subnet holds 2 fewer devices than expected2h − 2
Not counting the router interface/27 is chosen for 30 PCs and the router does not fithosts = computers + routers + printers + spare
Applying the magic number to the wrong octetIn /20, dividing the 4th octet by 16In /17–/23 the interesting octet is the 3rd; in /25–/30 it is the 4th
Broadcast = the next network addressa host is given the next subnet’s addressbroadcast = next network − 1
Giving the network address to a host (for example, .64/26)Windows warns or the device does not workfirst host = network + 1
“Adjacent addresses mean the same subnet”.62 and .65 are in different subnets in /26always calculate the network address and compare

Boss level

Boss level: subnet table generator

Build a complete table for the administrator. Input: a network (for example, 192.168.10.0/24) and the number of hosts H needed in each subnet. All subnets have the same size (FLSM), and the prefix is the largest one (i.e. the one giving the most subnets) that fits H hosts. Output:

Prefiks: /26, subnetlar: 4, xost/subnet: 62
1 192.168.10.0 192.168.10.1 192.168.10.62 192.168.10.63
2 192.168.10.64 192.168.10.65 192.168.10.126 192.168.10.127
...

On each line: the sequence number, network, first host, last host, broadcast (separated by spaces). If H hosts do not fit in the given network at all — Sig‘maydi. If there are more than 16 subnets, print only the first 16 and at the end write ... jami N ta. +50 XP

Reinforcement

Review questions

What is subnetting and what problems does it solve?

Splitting one network into smaller segments. It reduces broadcast traffic, improves security and management, and allows economical use of addresses.

How are the mask and the prefix related?

The prefix is the number of consecutive 1s in the mask: 255.255.255.192 = /26.

How is the network address found using the AND operation?

The IP and the mask are ANDed bit by bit: the bits under the mask’s 1s are kept, and the host bits become 0.

How is the magic number (block size) calculated and why is it needed?

256 − the interesting octet of the mask. Subnets start at this step; network = (octet // block) × block, broadcast = network + block − 1.

Write the formulas for the number of subnets and hosts.

Subnets: 2s (s — borrowed bits); hosts: 2h − 2 (h — host bits).

If 100 hosts are needed in each subnet, which prefix is chosen?

27 − 2 = 126 ≥ 100 → h = 7 → /25.

Why are the network and broadcast addresses not assigned to hosts?

The network address denotes the subnet itself (in routing tables), and broadcast is the address for sending to all devices in that subnet.

What is the drawback of FLSM? (a bridge to practical 4)

All subnets have the same size: a department with 200 hosts and a router link with 2 addresses get the same block — addresses are wasted. The solution is VLSM.

Independent work

Independent-study topic in the course program: “IPv4 addressing, subnetting and efficient planning of IP addresses” (6 hours). The part related to this class is equal-size subnetting (FLSM). VLSM planning is in the independent work of practical 4.

  1. Split the network in your variant into equal subnets according to the requirement: borrowed bits, the new mask (binary and decimal), the magic number.
  2. Build the full subnet table by hand (network, first/last host, broadcast).
  3. Using the AND operation (in bits), show which subnet the given test address belongs to.
  4. Check the result with your “Subnet table” program and attach a screenshot.
Assessment criteria (individual assignment)
CriterionPoints
Borrowed bits, mask and magic number are correct1
The subnet table is built by hand without errors2
The test address is correctly analyzed with AND1
The result of checking with the program is attached1

Summary

SubnettingBorrowing host bits to split a network into small segments.
Mask ↔ prefixPrefix = the number of 1s in the mask; the 1s must be consecutive.
ANDIP AND mask = network address; setting the host bits to 1 gives the broadcast.
Magic number256 − the interesting octet; network = (octet // block) × block.
2ˢ and 2ʰ − 2Formulas for the number of subnets and hosts.
Prefix from a requirementHost requirement → h, subnet requirement → s; count the router too.
FLSMAll subnets are equal — simple, but wasteful. The next step is VLSM (practical 4).

Your lesson results

Your results are saved in this browser. Read all the sections and complete the exercises and assignments.

My personal notes