Tutorials Logic, IN info@tutorialslogic.com

Subnetting Subnet Mask, CIDR, VLSM

Why Subnetting?

Subnetting is the process of dividing a large network into smaller, more manageable sub-networks (subnets). Benefits include:

  • Reduces network congestion (smaller broadcast domains)
  • Improves security (isolate network segments)
  • Efficient use of IP address space
  • Easier network management and troubleshooting

Subnet Mask and CIDR Notation

A subnet mask is a 32-bit number that separates the network portion from the host portion of an IP address. It uses 1s for the network bits and 0s for the host bits.

CIDR (Classless Inter-Domain Routing) notation expresses the subnet mask as a prefix length (number of 1 bits).

Formula: Usable hosts = 2n - 2, where n = number of host bits. We subtract 2 for the network address and broadcast address.

CIDR Subnet Mask Network Bits Host Bits Usable Hosts
/8 255.0.0.0 8 24 16,777,214
/16 255.255.0.0 16 16 65,534
/24 255.255.255.0 24 8 254
/25 255.255.255.128 25 7 126
/26 255.255.255.192 26 6 62
/27 255.255.255.224 27 5 30
/28 255.255.255.240 28 4 14
/29 255.255.255.248 29 3 6
/30 255.255.255.252 30 2 2

Subnetting Example: /24 Network

Given network: 192.168.1.0/24

  • Network Address: 192.168.1.0 (all host bits = 0)
  • Broadcast Address: 192.168.1.255 (all host bits = 1)
  • Usable Host Range: 192.168.1.1 - 192.168.1.254
  • Number of Usable Hosts: 28 - 2 = 254

Dividing /24 into Subnets

Divide 192.168.1.0/24 into 4 equal subnets (/26):

Subnet Network Address Broadcast Host Range Hosts
1 192.168.1.0/26 192.168.1.63 192.168.1.1 - .62 62
2 192.168.1.64/26 192.168.1.127 192.168.1.65 - .126 62
3 192.168.1.128/26 192.168.1.191 192.168.1.129 - .190 62
4 192.168.1.192/26 192.168.1.255 192.168.1.193 - .254 62

VLSM (Variable Length Subnet Masking)

VLSM allows using different subnet masks for different subnets within the same network, enabling more efficient use of IP addresses. Instead of dividing a network into equal-sized subnets, you allocate exactly the right size for each subnet.

Example: You have 192.168.1.0/24 and need:

  • Subnet A: 100 hosts -> use /25 (126 hosts) -> 192.168.1.0/25
  • Subnet B: 50 hosts -> use /26 (62 hosts) -> 192.168.1.128/26
  • Subnet C: 25 hosts -> use /27 (30 hosts) -> 192.168.1.192/27
  • Subnet D: 10 hosts -> use /28 (14 hosts) -> 192.168.1.224/28

Subnetting packet-flow walkthrough

Subnetting packet-flow walkthrough
Client device
  -> local network interface
  -> default gateway or switch
  -> routing/security decision
  -> destination service

For Subnetting, explain each hop by naming the address, protocol, port, and decision made at that layer.

Split a /24 into Four Equal IPv4 Subnets

Split a /24 into Four Equal IPv4 Subnets
from ipaddress import ip_network

network = ip_network('198.51.100.0/24')
for subnet in network.subnets(new_prefix=26):
    hosts = list(subnet.hosts())
    print(subnet, hosts[0], hosts[-1])
Output
198.51.100.0/26 198.51.100.1 198.51.100.62
198.51.100.64/26 198.51.100.65 198.51.100.126
198.51.100.128/26 198.51.100.129 198.51.100.190
198.51.100.192/26 198.51.100.193 198.51.100.254
Before you move on

Subnetting Subnet Mask, CIDR, VLSM Mastery Check

4 checks
  • Subnetting is the process of dividing a large network into smaller, more manageable sub-networks (subnets).
  • A subnet mask is a 32-bit number that separates the network portion from the host portion of an IP address.
  • It uses 1s for the network bits and 0s for the host bits.
  • Formula: Usable hosts = 2n - 2, where n = number of host bits.

Networking Questions Learners Ask

A /24 leaves eight host bits, while /26 borrows two of them for subnetting. Two borrowed bits create four combinations, producing four blocks of 64 addresses each.

Calculate the network address and ending address for each prefix, then compare the ranges. For example, 10.0.0.0/24 contains every address from 10.0.0.0 through 10.0.0.255, so 10.0.0.128/25 overlaps it completely.

Large requirements have fewer valid aligned locations. Allocating small networks first can fragment the address space and leave no contiguous block for the largest subnet. Sort requirements by host count, choose the smallest fitting prefix for each, and advance on valid block boundaries.

Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.