0Pricing
Linux Networking & TCP/IP for Developers · Lesson

Subnetting and CIDR in Depth

Master variable-length subnet masking and CIDR notation to plan address space, calculate ranges, and aggregate routes efficiently.

Subnetting and CIDR in Depth is a free Linux Networking & TCP/IP for Developers lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Networking & TCP/IP for Developers learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Subnetting Matters

Subnetting splits a large network into smaller, manageable segments. It improves security, performance, and address efficiency.

CIDR (Classless Inter-Domain Routing) replaced rigid class A/B/C boundaries with flexible prefix lengths.

CIDR Notation

A CIDR block is written as address/prefix. The prefix counts the number of leading network bits.

  • 192.168.1.0/24 — 24 network bits, 8 host bits
  • 10.0.0.0/8 — 8 network bits, 24 host bits

The Subnet Mask

A prefix maps directly to a dotted-decimal mask.

  • /24 = 255.255.255.0
  • /26 = 255.255.255.192
  • /30 = 255.255.255.252

Each set bit in the mask is a network bit.

Counting Hosts

Host count = 2^(host bits) minus 2 (network and broadcast addresses).

  • /24 -> 2^8 - 2 = 254 hosts
  • /26 -> 2^6 - 2 = 62 hosts
  • /30 -> 2^2 - 2 = 2 hosts (perfect for point-to-point links)

Finding the Network Address

Bitwise-AND the IP with the mask to get the network address. The example below computes it in Python.

import ipaddress
net = ipaddress.ip_network('192.168.5.130/26', strict=False)
print('network:', net.network_address)
print('broadcast:', net.broadcast_address)

Determining the Range

For 192.168.5.130/26: block size is 64, so subnets start at .0, .64, .128, .192.

The .130 address falls in the 192.168.5.128/26 subnet (usable .129 to .190, broadcast .191).

Variable-Length Subnet Masking (VLSM)

VLSM lets different subnets use different prefix lengths from one block, matching size to need.

Allocate largest subnets first to avoid fragmentation and wasted address space.

Route Aggregation (Supernetting)

Adjacent subnets can be summarized into one larger prefix, shrinking routing tables.

  • 192.168.0.0/24 + 192.168.1.0/24 -> 192.168.0.0/23

Aggregation only works when blocks are contiguous and aligned.

Subnetting with Python

The ipaddress module can split a network into smaller subnets automatically.

import ipaddress
big = ipaddress.ip_network('10.0.0.0/24')
for sub in big.subnets(new_prefix=26):
    print(sub)

Checking Membership

Verify whether an address belongs to a network — essential for ACLs and routing decisions.

import ipaddress
addr = ipaddress.ip_address('10.0.0.45')
net = ipaddress.ip_network('10.0.0.0/26')
print(addr in net)

Common Pitfalls

Watch out for:

  • Forgetting to subtract network and broadcast addresses
  • Misaligned aggregation that overlaps other blocks
  • Using /31 links (valid per RFC 3021 for point-to-point) without device support

Quick Check

Test your subnetting math.

Recap

You can now plan address space confidently:

  • Read and convert CIDR prefixes and masks
  • Calculate network, broadcast, and host ranges
  • Apply VLSM to size subnets to need
  • Aggregate contiguous blocks to shrink routing tables
  • Use Python's ipaddress module for verification

This underpins the IPv6, routing, and NAT topics in this course.

Frequently asked questions

Is the “Subnetting and CIDR in Depth” lesson free?

Yes — the full text of “Subnetting and CIDR in Depth” is free to read here on the web, and the Linux Networking & TCP/IP for Developers course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Networking & TCP/IP for Developers course, upgrade to CoddyKit PRO.

What will I learn in “Subnetting and CIDR in Depth”?

Master variable-length subnet masking and CIDR notation to plan address space, calculate ranges, and aggregate routes efficiently. You practise Linux Networking & TCP/IP for Developers with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Linux Networking & TCP/IP for Developers?

No prior experience is required. Linux Networking & TCP/IP for Developers on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Subnetting and CIDR in Depth” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Linux Networking & TCP/IP for Developers lesson?

Yes. Every Linux Networking & TCP/IP for Developers lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. IPv6 Addressing & Concepts
  2. Advanced Routing Protocols (RIP/OSPF)
  3. Network Address Translation (NAT)
  4. Subnetting and CIDR in Depth
← Back to Linux Networking & TCP/IP for Developers