PHASE 3 · MODULE 2

IP Addressing & Subnetting Mastery

From binary fundamentals to rapid subnet calculations — everything you need to design and debug IP networks.

Learning Objectives

IPv4 Structure

An IPv4 address is a 32-bit number expressed as four decimal octets separated by dots (dotted-decimal notation). Each octet ranges from 0 to 255.

// 32-bit IPv4 address — 4 octets, 8 bits each 192.168.1.100 // Binary representation: 11000000.10101000.00000001.01100100 ↑ octet 1 ↑ octet 2 ↑ octet 3 ↑ octet 4
1
1
0
0
0
0
0
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
1
0
1
1
0
0
1
0
0
Value = Σ (bit × 2^(7-n))
Each bit position represents a power of 2: 128, 64, 32, 16, 8, 4, 2, 1
Bit PositionPower of 2Decimal Value
1st (MSB)2^7128
2nd2^664
3rd2^532
4th2^416
5th2^38
6th2^24
7th2^12
8th (LSB)2^01

IPv4 Address Classes

Classful addressing divides IPv4 space into five classes based on the leading bits of the first octet.

ClassLeading BitsFirst Octet RangeDefault MaskNetwork/Host SplitUse Case
A0xxx xxxx1 – 126/8 (255.0.0.0)Net.Host.Host.HostLarge organizations
B10xx xxxx128 – 191/16 (255.255.0.0)Net.Net.Host.HostMedium organizations
C110x xxxx192 – 223/24 (255.255.255.0)Net.Net.Net.HostSmall networks
D1110 xxxx224 – 239—MulticastMulticast groups
E1111 xxxx240 – 255—ReservedResearch/experimental
Pitfall: 127.x.x.x is reserved for loopback (127.0.0.1 = localhost). Class A effectively starts at 1.0.0.0 and ends at 126.255.255.255. 0.0.0.0 and 255.255.255.255 have special meanings (default route and broadcast respectively).

CIDR Notation (Classless Inter-Domain Routing)

CIDR replaced classful addressing in 1993. It uses a /prefix-length suffix to indicate how many bits are fixed as the network portion.

CIDRSubnet MaskBroadcast MaskTotal IPsUsable Hosts
/8255.0.0.011111111.00000000.00000000.0000000016,777,21616,777,214
/16255.255.0.011111111.11111111.00000000.0000000065,53665,534
/24255.255.255.011111111.11111111.11111111.00000000256254
/25255.255.255.128—128126
/26255.255.255.192—6462
/27255.255.255.224—3230
/28255.255.255.240—1614
/29255.255.255.248—86
/30255.255.255.252—42
Usable Hosts = 2^h − 2
Where h = number of host bits (32 − prefix length). Subtract 2 for network ID and broadcast address.

Binary-to-Decimal Quick Reference

PrefixInteresting Octet ValueIncrement/Borrow
/24255.255.255.0— (boundary)
/25255.255.255.128128
/26255.255.255.19264
/27255.255.255.22432
/28255.255.255.24016
/29255.255.255.2488
/30255.255.255.2524

Subnet Calculation — Step by Step

Given: 192.168.10.0/26 — Find network address, broadcast, usable range, and host count.

  1. Identify the "interesting octet." /26 means 26 network bits span 3 full octets (24 bits) + 2 bits into the 4th octet. The 4th octet is interesting.
  2. Find the mask for the interesting octet. 26 − 24 = 2 network bits → 1100 0000 = 128 + 64 = 192. Subnet mask: 255.255.255.192
  3. Calculate the increment (block size). 256 − 192 = 64. Subnets increase by 64 in the 4th octet.
  4. List the subnets. 0, 64, 128, 192 — giving us four /26 subnets.
  5. For 192.168.10.0/26: Network = 192.168.10.0, Broadcast = 192.168.10.63, Usable range = 192.168.10.1 – 192.168.10.62, Hosts = 2^6 − 2 = 62.
Fast Subnet Cheat Sheet

memorize the power-of-2 table and the magic number trick:
Magic Number = 256 − interesting octet mask value
Subnet boundaries are multiples of the magic number in that octet.

Subnetting Practice Problems

Problem 1: Analyze 172.16.0.0/20

Interesting octet: 2nd (20 bits spans 1 full octet + 4 into 2nd)

Mask: 1111 0000 = 240 → 255.255.240.0

Magic number: 256 − 240 = 16

Subnets in 2nd octet: 0, 16, 32, 48, ... 240 (16 subnets total)

First subnet: Network = 172.16.0.0, Broadcast = 172.16.15.255

Usable hosts: 2^(32−20) − 2 = 2^12 − 2 = 4,094

Usable range: 172.16.0.1 – 172.16.15.254

Problem 2: You need 50 subnets from 10.0.0.0/8. What's the new prefix?

Required subnets: 50 → need 2^n ≥ 50 → n = 6 bits (2^6 = 64)

New prefix: /8 + 6 borrowed = /14

New mask: 255.252.0.0 (11111100.00000000.00000000.00000000)

Hosts per subnet: 2^(32−14) − 2 = 2^18 − 2 = 262,142

Subnet increment: 256 − 252 = 4 in the 2nd octet

Problem 3: What is the broadcast address of 192.168.1.128/27?

Magic number: 256 − 224 = 32

Subnet boundaries in 4th octet: 0, 32, 64, 96, 128, 160, 192, 224

192.168.1.128 falls in the subnet starting at 128

Next subnet: 128 + 32 = 160

Broadcast address: 192.168.1.159 (one less than next subnet)

Usable range: 192.168.1.129 – 192.168.1.158

Usable hosts: 2^5 − 2 = 30

Problem 4: Divide 10.10.0.0/16 into 8 equal subnets. List the first two.

Borrowed bits: log2(8) = 3 → new prefix = /16 + 3 = /19

Mask: 255.255.224.0 (11100000 = 224 in 3rd octet)

Magic number: 256 − 224 = 32

Subnet 0: 10.10.0.0/19 — range 10.10.0.1 – 10.10.31.254, bcast 10.10.31.255

Subnet 1: 10.10.32.0/19 — range 10.10.32.1 – 10.10.63.254, bcast 10.10.63.255

Hosts per subnet: 2^(32−19) − 2 = 2^13 − 2 = 8,190

IPv6 Basics

IPv6 uses 128-bit addresses, providing approximately 3.4 × 10^38 unique addresses — enough for every grain of sand on Earth to have its own IP.

// Full IPv6 address (8 groups of 4 hex digits) 2001:0db8:85a3:0000:0000:8a2e:0370:7334 // Compressed form (leading zeros omitted, :: once) 2001:db8:85a3::8a2e:370:7334 // Common prefixes 2001:db8:: // Documentation (RFC 3849) ::1 // Loopback (equivalent to 127.0.0.1) fe80::/10 // Link-local unicast ff00::/8 // Multicast
FeatureIPv4IPv6
Address size32 bits (4.3 billion)128 bits (~3.4×10^38)
NotationDotted decimalHex colon-separated
ConfigurationManual or DHCPSLAAC (stateless) or DHCPv6
NATNecessary due to scarcityGenerally unnecessary
Headers20+ bytes, options variable40 bytes fixed, extensible
SecurityOptional (IPsec added later)Designed with IPsec in mind
FragmentationRouters can fragmentOnly source can fragment

Private vs Public IP Addresses

RangeClassCIDRNotes
10.0.0.0 – 10.255.255.255A/8Single /8 — largest private block
172.16.0.0 – 172.31.255.255B/12–/1616 contiguous /12 blocks
192.168.0.0 – 192.168.255.255C/16256 contiguous /24 networks — most common
100.64.0.0 – 100.127.255.255—/10Carrier-grade NAT (CGNAT, RFC 6598)
NAT (Network Address Translation)

NAT allows multiple private IPs to share a single public IP. When an internal host sends traffic out, the router replaces the private source IP with its public IP and tracks the translation in a NAT table. Return traffic is reverse-translated. Types include Static NAT (1:1 mapping), Dynamic NAT (pool-based), and NAPT/PAT (overloading — most common, using port numbers to distinguish sessions).

DHCP (Dynamic Host Configuration Protocol)

DHCP automatically assigns IP configuration to devices. The DORA process: Discover (client broadcasts), Offer (server responds with IP), Request (client requests the offered IP), Acquire (server confirms). Key concepts: scopes (range of assignable IPs), reservations (binding a MAC to a specific IP), leases (temporary assignment with renewal).

Common Pitfalls

Pitfall 1: Forgetting to subtract 2 for network and broadcast addresses. /24 always gives 254 usable hosts, not 256.
Pitfall 2: Confusing the subnet mask with the wildcard mask (used in ACLs). They are bitwise complements: mask 255.255.255.0 → wildcard 0.0.0.255.
Pitfall 3: Misidentifying the interesting octet. Count network bits: if /27, the 3rd octet is full (24 bits) + 3 bits in the 4th octet — the 4th is interesting.
Pitfall 4: Treating /31 and /32 as having usable hosts. /32 is a single host route. /31 (point-to-point per RFC 3021) has 0 usable hosts but is valid for point-to-point links.
Pitfall 5: IPv6 :: expansion errors. :: can only appear once in an address. 2001:db8::1:1 is valid but 2001::db8::1 is invalid.

Resources

← OSI & TCP/IP Models Next: Network Protocols →