In this blog, Iโll break down subnetting, show you how it works, and walk you through my subnetting project (complete with diagrams and code).
Letโs untangle the magic behind those /24, /16, and 255.255.255.0 masks. ๐ญ
๐ฆ Why Subnetting Matters
"Without subnetting, your networkโs like a city with no street names โ total chaos."
Imagine 10,000 devices trying to talk on the same street with no addresses. Thatโs what a flat IP network looks like.
Subnetting introduces:
- ๐ฆ Structure
- ๐ Routing efficiency
- ๐ Security boundaries
Letโs break it down ๐
๐ What is a Subnet?
A subnet (short for subnetwork) is a smaller network within a larger one, created by dividing an IP range using a subnet mask.
For example:
๐งฎ IP Address: 135.70.1.0
๐ญ Subnet Mask: 255.255.255.0
Weโre saying:
- First 3 octets = Network
- Last octet = Hosts
This helps:
- Routers ๐ know where to send packets
- Admins ๐งโ๐ป manage traffic flow between devices and regions
๐งฉ How Subnetting Works
A subnet mask splits the IP address into:
- ๐งฑ Network bits โ define the subnet
- ๐ Host bits โ define the actual devices
Think of each subnet like a neighborhood in a city:
Devices (houses) are easier to locate, control, and communicate within that area ๐ก
๐ธ Visual Aid:
๐ข IPv4 Classes and Subnet Masks
Hereโs a handy chart that shows the basics of IPv4 classes:
| ๐ท๏ธ Class | ๐ก๏ธ Subnet Mask | ๐ # of Networks | ๐ฅ Hosts per Network |
|---|---|---|---|
| A | 255.0.0.0 |
128 networks |
16,777,216 hosts |
| B | 255.255.0.0 |
16,384 networks |
65,536 hosts |
| C | 255.255.255.0 |
2,097,152 networks |
256 hosts |
๐ These classes define how many networks and hosts you can support. For example, Class C is often used in homes and small offices!
๐ ๏ธ How I Built My Own Subnet Planner in Go
Ever wanted to divide networks smartly for homes, offices, or cafรฉs? ๐ต๐ข๐ก
I created a Subnet Calculator in Go that:
- โ Accepts an IP address and the desired number of subnets
- ๐งฎ Calculates the new subnet mask
- โ๏ธ Splits the network accordingly
- ๐ Shows usable ranges for each area
โ๏ธ Go Code: Subnet Planner
package main
import (
"net"
"fmt"
)
func main() {
_, ipNet, err := net.ParseCIDR("192.168.0.0/16")
baseIP := ipNet.IP
oldPrefix, _ := ipNet.Mask.Size()
if err != nil {
panic(err)
}
newPrefix := 24
numSubsets := 1 << (newPrefix - oldPrefix)
var subnets []net.IPNet
for i := 0; i < numSubsets; i++ {
subnetIP := make(net.IP, len(baseIP))
copy(subnetIP, baseIP)
subnetIP[2] = byte(i)
subnet := net.IPNet{
IP: subnetIP,
Mask: net.CIDRMask(newPrefix, 32),
}
subnets = append(subnets, subnet)
}
areas := []string{"๐ home", "๐ข office", "โ cafe", "๐ณ park", "๐ library"}
for i, area := range areas {
if i < len(subnets) {
fmt.Printf("%-10s : %s\n", area, subnets[i].String())
}
}
}
This prints subnet blocks for each area like:
- ๐ home : 192.168.0.0/24
- ๐ข office : 192.168.1.0/24
- โ cafe : 192.168.2.0/24
- ๐ณ park : 192.168.3.0/24
- ๐ library : 192.168.4.0/24
โ Conclusion
Subnetting isnโt just for network engineers โ itโs for anyone building smart systems.
Whether youโre setting up:
- ๐ป A small office LAN
- ๐ซ A school Wi-Fi plan
- โ๏ธ A cloud VPC setup
Subnetting gives you:
- ๐ถ Scalability
- ๐ Security zones
- ๐ Faster routing
And hey, once you get the hang of it โ itโs kinda fun ๐

Top comments (2)
Thankyou.