Skip to main content

Subnetting (IPv4)

Subnetting Basics

Subnetting divides a large network into smaller, more manageable sub-networks (subnets). This improves performance, organization, and security.

TermSymbol/RefDefinitionExample
IP AddressIPUnique address of a device on the network.192.168.1.10
Subnet MaskNetmaskSeparates the Network part from the Host part.255.255.255.0
CIDRSlash Not.Short format of the mask (Count of "1" bits)./24
Network IDNet IDThe "Street Name". The first address of the subnet.192.168.1.0
BroadcastBcastCall to all devices. The last address.192.168.1.255
HostHostA device (PC, Router) inside the subnet..1 to .254
Network-BitsNet-BitsBits in the IP address identifying the network./24 => first 24 bits
Host-BitsHost-BitsBits in the IP address identifying hosts within the network.24 => last 8 bits

Rule: An IPv4 address consists of 32 Bits, divided into 4 Octets (8 bits each).
Format: x.x.x.x (Decimal) or 11000000.10101000.00000001.00001010 (Binary)


Understanding Subnet Masks & CIDR

The Subnet Mask tells the computer which part of the IP is the Network (Street) and which part is the Host (House Number).

CIDR Notation (Classless Inter-Domain Routing)

CIDR (e.g., /24) simply counts the number of active bits in the mask from left to right.

CIDRDecimal Subnet MaskBinary Subnet Mask (First Octets)Hosts per Subnet*
/8255.0.0.011111111.00000000...16,777,214
/16255.255.0.011111111.11111111...65,534
/24255.255.255.011111111...11111111.0254
/25255.255.255.12811111111...1.10000000126
/26255.255.255.19211111111...1.1100000062
/30255.255.255.25211111111...1.111111002

Note: Total addresses minus 2 (1 for Network ID, 1 for Broadcast).


Calculation Methods

1. Calculating Subnet Size (Number of Hosts)

How many devices fit into a subnet?

Formula: 2^(Host-Bits) - 2 = Usable Hosts

Host-Bits = 32 - (CIDR)

Example: /24 Network

  1. Host-Bits: 32 - 24 = 8 Bits
  2. Calculation: 2⁸ = 256
  3. Usable: 256 - 2 = 254 Hosts

Example: /26 Network

  1. Host-Bits: 32 - 26 = 6 Bits
  2. Calculation: 2⁶ = 64
  3. Usable: 64 - 2 = 62 Hosts

2. Finding the "Magic Number" (Size of each Subnet)

The Magic Number helps you calculate subnet ranges mentally. It represents the increment (step size) of the networks.

Method 1 (Binary Place):
Look at the last bit set to '1' in the subnetmask. Its value is the Magic Number.

Method 2 (Subtraction):
256 - (Last non-zero octet of the mask) = Magic Number

Example: /26 Mask (255.255.255.192)

  • Interesting Octet: 192
  • Calculation: 256 - 192 = 64
  • Result: The networks increase in steps of 64 (0, 64, 128, 192).

Step-by-Step Example Calculation

Task: Analyze the IP 192.168.10.150 with the mask 255.255.255.192 (/26).

Step 1: Find the Magic Number (Block Size)

  • Mask is /26. The change happens in the 4th Octet.
  • Mask in 4th Octet: 192
  • Magic Number: 256 - 192 = 64

Step 2: Determine Subnet Ranges

Increment by 64 until you pass the IP address (150).

  • Subnet 1: 0 - 63
  • Subnet 2: 64 - 127
  • Subnet 3: 128 - 191 (150 falls into this range)
  • Subnet 4: 192 - 255

Step 3: Calculate Addresses

The IP 192.168.10.150 belongs to the .128 Subnet.

TypeCalculationResult
Network IDStart of the block192.168.10.128
First HostNetwork ID + 1192.168.10.129
Last HostBroadcast - 1192.168.10.190
BroadcastNext Block (192) - 1192.168.10.191

Quick Reference: Common Subnets

CIDRMask (.x)Magic NumberUsable HostsTypical Use Case
/24.0256254Standard LAN (Home/Office)
/25.128128126Splitting a LAN in half
/26.1926462Department networks
/27.2243230Small Teams
/28.2401614Very small groups
/29.24886Transfer nets (Router-to-Router)
/30.25242Point-to-Point Links
/32.25511Single Host IP (Loopback)

Common Pitfalls

  • Forgetting ID/Broadcast: Always subtract 2 to get usable hosts.

  • Wrong stepping: Subnet ranges are inclusive. The first subnet therefore ends at start + block size − 1. Once the first subnet is correct, subsequent subnet ends can be calculated either by adding the block size to the previous subnet end, or by applying the same start + block size − 1 formula using the network address of each subnet.

  • Wrong Octet: A /18 subnet changes in the 3rd octet, not the 4th.

  • /8 - /15: Change in 2nd Octet

  • /16 - /23: Change in 3rd Octet

  • /24 - /32: Change in 4th Octet

  • Even/Odd: Network IDs are usually even numbers; Broadcasts are usually odd numbers.