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.
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)
- 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.
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.
| Prefix | Mask | Last octet (binary) | Magic number | Subnets within /24 | Hosts/subnet |
|---|---|---|---|---|---|
| /24 | 255.255.255.0 | 00000000 | 256 | 1 | 254 |
| /25 | 255.255.255.128 | 10000000 | 128 | 2 | 126 |
| /26 | 255.255.255.192 | 11000000 | 64 | 4 | 62 |
| /27 | 255.255.255.224 | 11100000 | 32 | 8 | 30 |
| /28 | 255.255.255.240 | 11110000 | 16 | 16 | 14 |
| /29 | 255.255.255.248 | 11111000 | 8 | 32 | 6 |
| /30 | 255.255.255.252 | 11111100 | 4 | 64 | 2 |
Number of subnets
2s, where s is the number of borrowed bits.
Number of hosts
2h − 2, where h is the number of remaining host bits (h = 32 − prefix).
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
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)
- Convert the prefix to a mask
/26 → 26 ones:
11111111.11111111.11111111.11000000= 255.255.255.192. - 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. - The AND operation
01001101AND11000000=01000000= 64. Network address: 192.168.10.64. - 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)
- Magic number
The mask’s “interesting” octet is 192 → 256 − 192 = 64. Subnets: .0, .64, .128, .192.
- Which block does the IP fall into?
Divide 77 by 64: 77 // 64 = 1 → 1 × 64 = 64. Network: 192.168.10.64.
- Subtract one from the next block
The next subnet is .128 → broadcast = 128 − 1 = .127. Hosts .65 – .126.
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
- How many bits are borrowed?
2s ≥ 4 → s = 2. New prefix: 24 + 2 = /26 (255.255.255.192).
- Are there enough hosts?
Host bits 32 − 26 = 6 → 26 − 2 = 62 hosts in each subnet.
- A table using the block size
We write it out with a step of 256 − 192 = 64:
| № | Network | First host | Last host | Broadcast | Assigned to |
|---|---|---|---|---|---|
| 1 | 192.168.10.0/26 | .1 | .62 | .63 | Dean’s office |
| 2 | 192.168.10.64/26 | .65 | .126 | .127 | Computer lab |
| 3 | 192.168.10.128/26 | .129 | .190 | .191 | Library |
| 4 | 192.168.10.192/26 | .193 | .254 | .255 | Guest 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
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
| Error | Consequence | Correct answer |
|---|---|---|
| Taking the number of hosts to be 2h | the subnet holds 2 fewer devices than expected | 2h − 2 |
| Not counting the router interface | /27 is chosen for 30 PCs and the router does not fit | hosts = computers + routers + printers + spare |
| Applying the magic number to the wrong octet | In /20, dividing the 4th octet by 16 | In /17–/23 the interesting octet is the 3rd; in /25–/30 it is the 4th |
| Broadcast = the next network address | a host is given the next subnet’s address | broadcast = next network − 1 |
| Giving the network address to a host (for example, .64/26) | Windows warns or the device does not work | first host = network + 1 |
| “Adjacent addresses mean the same subnet” | .62 and .65 are in different subnets in /26 | always 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.
- Split the network in your variant into equal subnets according to the requirement: borrowed bits, the new mask (binary and decimal), the magic number.
- Build the full subnet table by hand (network, first/last host, broadcast).
- Using the AND operation (in bits), show which subnet the given test address belongs to.
- Check the result with your “Subnet table” program and attach a screenshot.
| Criterion | Points |
|---|---|
| Borrowed bits, mask and magic number are correct | 1 |
| The subnet table is built by hand without errors | 2 |
| The test address is correctly analyzed with AND | 1 |
| The result of checking with the program is attached | 1 |
Summary
Your lesson results
Your results are saved in this browser. Read all the sections and complete the exercises and assignments.