IPv4 Addressing
IPv4 Address Structure
An IPv4 address is a 32-bit binary value used to uniquely identify a device on a network. To make it human-readable, these 32 bits are divided into four groups of 8 bits called octets, written in dotted decimal notation as W.X.Y.Z. Each octet can range from 0 to 255, since 8 bits can represent 2^8 = 256 values.
An IPv4 address has two portions: the network portion, which identifies which network the device belongs to, and the host portion, which identifies the specific device within that network. The subnet mask defines the boundary between these two portions.
The subnet mask can be written in two equivalent ways. Dotted decimal notation looks like an IP address: 255.255.255.0. Prefix length (CIDR) notation uses a forward slash followed by the count of network bits: /24. Both mean the same thing — the first 24 bits are the network portion.
Subnet Mask and Logical AND
The subnet mask is also a 32-bit value. It has all 1s in the network portion and all 0s in the host portion. This binary structure is what makes the Logical AND operation work — ANDing any bit with 1 preserves it, and ANDing any bit with 0 forces a 0.
Common subnet masks: /8 = 255.0.0.0 (Class A), /16 = 255.255.0.0 (Class B), /24 = 255.255.255.0 (Class C). The Logical AND of an IP address and its subnet mask always produces the Network Address.
IP Address: 192.168.10.50 Binary: 11000000.10101000.00001010.00110010 Subnet Mask: 255.255.255.0 Binary: 11111111.11111111.11111111.00000000 AND Result: (keep bits where mask=1, zero bits where mask=0) Network Addr: 11000000.10101000.00001010.00000000 = 192.168.10.0 (Network Address)
The AND operation is straightforward: 1 AND 1 = 1, 1 AND 0 = 0, 0 AND 1 = 0, 0 AND 0 = 0. The host portion bits are all zeroed out, leaving only the network address. This is how routers determine which network a packet belongs to before making forwarding decisions.
Network, Host, and Broadcast Addresses
Within any subnet, three address types are reserved and cannot be assigned to hosts. Understanding these is essential for correct IP planning and is tested heavily on the CCNA exam.
The network address has all host bits set to 0. It identifies the subnet itself — for example, 192.168.10.0/24. The broadcast address has all host bits set to 1 — for example, 192.168.10.255/24. Every host on the subnet receives a packet sent to the broadcast address. The usable host range is everything between these two.
The formula for usable hosts is 2^n − 2, where n is the number of host bits. For a /24 subnet: 2^8 − 2 = 254 usable hosts. The −2 accounts for the network address and the broadcast address.
Unicast, Broadcast, and Multicast
IPv4 supports three types of communication, each designed for different traffic patterns. Understanding these distinctions is important for network design and for the CCNA exam.
Unicast is one-to-one communication — a packet sent from one specific host to one specific destination host. This is the most common form of IPv4 traffic (web browsing, file transfer, SSH). Broadcast sends a packet to all hosts on a network segment. Multicast enables one-to-many communication where only subscribed hosts receive the traffic.
Broadcast has two sub-types: the limited broadcast address 255.255.255.255 is never forwarded by routers and reaches only the local subnet. The directed broadcast (e.g., 192.168.10.255 for the /24 subnet) can theoretically cross routers but is disabled by default on Cisco routers for security reasons. Multicast addresses fall in the range 224.0.0.0 – 239.255.255.255. Well-known multicast addresses include 224.0.0.5 (OSPF routers), 224.0.0.9 (RIP routers), and 224.0.0.18 (VRRP).
Public and Private IPv4 Addresses
Not all IPv4 addresses are routable on the public internet. RFC 1918 defines three private address ranges that organisations can use internally without registration. These addresses are deliberately non-routable on the internet — ISP routers drop packets with private source addresses. NAT (Network Address Translation) bridges the gap, translating private addresses to a public IP for internet access.
Class A private range: 10.0.0.0 – 10.255.255.255 (/8) — over 16 million addresses, used by large enterprises. Class B private range: 172.16.0.0 – 172.31.255.255 (/12) — about 1 million addresses. Class C private range: 192.168.0.0 – 192.168.255.255 (/16) — 65,536 addresses, the most common in homes and small offices.
Special-purpose addresses you must know: Loopback 127.0.0.0/8 (127.0.0.1 is localhost — used to test the TCP/IP stack on the local device). APIPA 169.254.0.0/16 — automatically assigned when DHCP fails. Shared/CGNAT 100.64.0.0/10 — used by ISPs for Carrier-Grade NAT.
Subnetting — Basic Concepts
Subnetting divides a larger network into smaller subnetworks (subnets). This reduces broadcast domains (keeping broadcasts contained to smaller groups), improves security (separate subnets for different departments), and makes more efficient use of IP addresses by sizing subnets to actual host requirements.
Subnetting works by borrowing bits from the host portion of an address to extend the network portion. Each borrowed bit doubles the number of subnets but halves the number of hosts per subnet. The formula for number of subnets is 2^s where s = number of borrowed bits, and hosts per subnet is 2^h − 2 where h = remaining host bits.
Example: Take 192.168.1.0/24 and subnet it into /26 networks. We borrow 2 bits (26 − 24 = 2), creating 2^2 = 4 subnets. Each subnet has 6 host bits remaining: 2^6 − 2 = 62 usable hosts.
Network Usable Range Broadcast 192.168.1.0/26 192.168.1.1 – 192.168.1.62 192.168.1.63 192.168.1.64/26 192.168.1.65 – 192.168.1.126 192.168.1.127 192.168.1.128/26 192.168.1.129– 192.168.1.190 192.168.1.191 192.168.1.192/26 192.168.1.193– 192.168.1.254 192.168.1.255 Block size = 64 (2^6). Subnets start at 0, 64, 128, 192. Each subnet: 62 usable hosts. Total: 4 × 62 = 248 hosts.
VLSM — Variable Length Subnet Masking
VLSM (Variable Length Subnet Masking) allows a network administrator to use different subnet sizes within the same address block. Without VLSM (fixed-length subnetting), every subnet must be the same size — this wastes addresses when subnets have very different host requirements. VLSM solves this by tailoring each subnet exactly to its needs.
The critical rule of VLSM: always allocate the largest subnet first, then progressively smaller ones. This prevents overlapping address spaces. Starting with the next available address block after each allocation ensures subnets never collide.
Example: A company needs 4 LANs with 50, 25, 10, and 2 hosts respectively, plus a WAN link. Starting address: 192.168.5.0/24.
Requirement Need Prefix Subnet Assigned Hosts Available LAN1 (50 h) /26 192.168.5.0/26 62 hosts (.0–.63) LAN2 (25 h) /27 192.168.5.64/27 30 hosts (.64–.95) LAN3 (10 h) /28 192.168.5.96/28 14 hosts (.96–.111) WAN (2 h) /30 192.168.5.112/30 2 hosts (.112–.115) Remaining free space: 192.168.5.116 – 192.168.5.255 (140 addresses)
Subnet Mask Quick Reference
The table below shows the most common prefix lengths used in subnetting. Notice how each step up in prefix length (more network bits) halves the number of available hosts. The /30 prefix is the standard choice for point-to-point WAN links between two routers, providing exactly 2 usable addresses.
172.16.0.0/16. Design VLSM subnets for the following requirements:• Engineering dept: 500 hosts
• Sales dept: 200 hosts
• HR dept: 100 hosts
• Management dept: 50 hosts
• WAN Link 1 (HQ to Branch 1): 2 hosts
• WAN Link 2 (HQ to Branch 2): 2 hosts
• WAN Link 3 (Branch 1 to Branch 2): 2 hosts
Task: For each subnet, determine the correct prefix length, the subnet address, the usable host range, and the broadcast address. Work from largest to smallest requirement.
💡 Show hints & approach
- 500 hosts → need /23 (2^9−2=510 usable). Start: 172.16.0.0/23
- 200 hosts → need /24 (2^8−2=254 usable). Next: 172.16.2.0/24
- 100 hosts → need /25 (2^7−2=126 usable). Next: 172.16.3.0/25
- 50 hosts → need /26 (2^6−2=62 usable). Next: 172.16.3.128/26
- Each WAN link → /30 (2 usable hosts). Next three /30s after the /26
- Remember: block size for /23 is 512, /24 is 256, /25 is 128, /26 is 64, /30 is 4