Subnet Masks and CIDR: Complete IP Subnetting Guide

Master network subnetting and CIDR notation. Learn how subnet masks divide networks, calculate IP ranges, understand CIDR notation, and design efficient network architectures. Essential for understanding IP addressing and managing network infrastructure.

What is a Subnet Mask?

A subnet mask is a 32-bit number that divides an IP address into network and host portions. It determines which part of the IP address identifies the network and which part identifies the specific device on that network.

IP Address + Subnet Mask Breakdown

IP Address: 192.168.1.100
Subnet Mask: 255.255.255.0
Network Portion (255 = all 1s)
192.168.1 identifies the network
Host Portion (0 = all 0s)
.100 identifies the device
Result: All devices with 192.168.1.x are on the same network and can communicate directly. Different networks (like 192.168.2.x) need a router to communicate.

Binary Representation

IP: 11000000.10101000.00000001.01100100
Mask: 11111111.11111111.11111111.00000000
Network bits = 1, Host bits = 0

Common Subnet Masks

255.255.255.0/24 (254 hosts)
255.255.0.0/16 (65,534 hosts)
255.0.0.0/8 (16,777,214 hosts)

CIDR Notation Explained

Classless Inter-Domain Routing (CIDR) is a compact way to specify IP addresses and their subnet masks. Instead of writing "255.255.255.0", you write "/24" - the number of network bits.

CIDR Notation Format

192.168.1.0/24
IP Address + Slash + Number of Network Bits
192.168.1.0/24
= 255.255.255.0
24 network bits, 8 host bits
10.0.0.0/16
= 255.255.0.0
16 network bits, 16 host bits
172.16.0.0/12
= 255.240.0.0
12 network bits, 20 host bits

CIDR Quick Reference Table

CIDRSubnet MaskUsable HostsTotal IPs
/30255.255.255.25224
/29255.255.255.24868
/28255.255.255.2401416
/27255.255.255.2243032
/26255.255.255.1926264
/25255.255.255.128126128
/24255.255.255.0254256
/16255.255.0.065,53465,536
/8255.0.0.016,777,21416,777,216
Note: Usable hosts = Total IPs - 2 (network address and broadcast address reserved)

Calculating Subnet Ranges

Understanding how to calculate network address, broadcast address, and usable host range is essential for subnet planning.

Example: 192.168.10.0/24

Network Information
CIDR:/24
Subnet Mask:255.255.255.0
Total IPs:256
Usable Hosts:254
Address Range
Network:192.168.10.0
First Host:192.168.10.1
Last Host:192.168.10.254
Broadcast:192.168.10.255

Key Addresses Explained

N
Network Address (.0)
Identifies the network itself. Cannot be assigned to a device. Used in routing tables.
H
Host Addresses (.1 to .254)
Assignable to devices (computers, servers, printers). First address often used for gateway/router.
B
Broadcast Address (.255)
Messages sent here reach all devices on the network. Cannot be assigned to a device.

Subnetting Examples

Example 1: Dividing a /24 Network

You have 192.168.1.0/24 and need to create 4 smaller subnets. Each subnet needs at least 50 hosts.

Solution: Use /26 (62 usable hosts each)
Subnet 1: 192.168.1.0/26
Range: .1 to .62
Subnet 2: 192.168.1.64/26
Range: .65 to .126
Subnet 3: 192.168.1.128/26
Range: .129 to .190
Subnet 4: 192.168.1.192/26
Range: .193 to .254

Example 2: Point-to-Point Links

Connecting two routers directly only needs 2 IP addresses. Use /30 to minimize waste.

10.0.0.0/30 (2 usable IPs)
10.0.0.0
Network address
10.0.0.1
Router A
10.0.0.2
Router B
10.0.0.3
Broadcast address

Example 3: VLSM (Variable Length Subnet Masking)

Different departments need different numbers of IPs. Use different subnet sizes efficiently.

Sales: 172.16.0.0/25
126 hosts for large department
126 IPs
IT: 172.16.0.128/27
30 hosts for medium department
30 IPs
Management: 172.16.0.160/28
14 hosts for small department
14 IPs

Private IP Address Ranges

RFC 1918 defines private IP ranges that can be used internally without coordination with IANA. These are never routed on the public internet.

10.0.0.0/8
10.0.0.0 - 10.255.255.255
16,777,216 IPs
Class A
Use case: Large enterprises, cloud providers, major networks. Lots of IP space.
172.16.0.0/12
172.16.0.0 - 172.31.255.255
1,048,576 IPs
Class B
Use case: Medium to large organizations. Good balance of size and manageability.
192.168.0.0/16
192.168.0.0 - 192.168.255.255
65,536 IPs
Class C
Use case: Home networks, small offices. Most home routers use 192.168.1.0/24 or 192.168.0.0/24.

Subnet Planning Best Practices

1. Plan for Growth

Always allocate more IPs than currently needed. A network that needs 20 devices today might need 50 tomorrow. Use /26 (62 hosts) instead of /27 (30 hosts).

Rule of thumb: Allocate 2-3x the current requirement, or 50% growth capacity

2. Use Hierarchical Addressing

Organize subnets logically by location, department, or function. Makes management and troubleshooting easier.

10.0.x.0/24 - Branch offices (x = location ID)
10.1.x.0/24 - Server VLANs (x = server type)
10.2.x.0/24 - Guest networks (x = building)

3. Document Everything

  • Maintain a subnet allocation spreadsheet or IPAM tool
  • Record subnet purpose, VLAN ID, and gateway address
  • Note date created and who requested it
  • Track IP assignments within each subnet

4. Avoid Overlap

Never create overlapping subnets. Use a subnet calculator to ensure no conflicts. Overlapping subnets cause routing failures and connectivity issues.

❌ Bad Example (Overlap):
192.168.1.0/24 (includes .0 to .255)
192.168.1.128/25 (includes .128 to .255) ← Overlaps!

5. Reserve Ranges for Special Use

  • .1: Typically the gateway/router
  • .2-.10: Network infrastructure (switches, APs)
  • .11-.99: Static assignments (servers, printers)
  • .100-.254: DHCP pool for workstations

Supernetting (Route Aggregation)

Supernetting is the opposite of subnetting - combining multiple networks into a single, larger network. Used to reduce routing table size and simplify network management.

Supernetting Example

Instead of advertising 4 separate routes:
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24
↓ Aggregate into ↓
Single supernet route:
192.168.0.0/22
Covers 192.168.0.0 through 192.168.3.255 (1,024 IPs)

Benefits

  • Smaller routing tables
  • Faster routing lookups
  • Reduced router memory usage
  • Less BGP update traffic

Requirements

  • Networks must be contiguous
  • Must be powers of 2
  • Requires CIDR support
  • Careful planning needed

Common Subnetting Mistakes

Forgetting Network and Broadcast Addresses

A /24 network has 256 IPs, but only 254 are usable. Always subtract 2 for network and broadcast addresses.

Not Planning for Growth

Using a /29 (6 hosts) for a department with 5 devices leaves no room for expansion. Plan ahead!

Creating Overlapping Subnets

Ensure new subnets don't overlap existing ones. Use a subnet calculator or IP address management tool.

Wrong Subnet Mask on Devices

If devices have incorrect subnet masks, they won't know which IPs are local vs remote, causing routing issues.

Subnetting Calculation Tips

Quick Formulas

Total IPs = 2^(32 - CIDR)
Example: /24 = 2^(32-24) = 2^8 = 256 IPs
Usable Hosts = Total IPs - 2
Example: 256 - 2 = 254 usable hosts
Number of Subnets = 2^(borrowed bits)
Example: /24 to /26 borrows 2 bits = 2^2 = 4 subnets

Binary Conversion Shortcuts

Bit PositionDecimal Value
1st bit128
2nd bit64
3rd bit32
4th bit16
5th bit8
6th bit4
7th bit2
8th bit1
Example: 255.255.255.192 = 11111111.11111111.11111111.11000000
Last octet: 128 + 64 = 192 (first 2 bits on)

Related Topics