IP addressing is the foundation of all network communication. IPv4 uses 32-bit addresses, IPv6 uses 128-bit. CIDR notation specifies network size. Subnetting divides large networks into smaller segments for security and performance.
| Item | Syntax / Value | Description |
|---|---|---|
| IPv4 | 32-bit address: 192.168.1.100 | Dotted decimal notation — 4 octets |
| IPv4 classes | A: 1-126, B: 128-191, C: 192-223 | Historical classful addressing — now replaced by CIDR |
| Private IPv4 | 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 | RFC 1918 — not routed on public internet |
| 127.0.0.0/8 | 127.0.0.1 = localhost | Loopback range — never leaves host |
| 169.254.0.0/16 | APIPA — auto-configured when no DHCP | Link-local — also AWS EC2 metadata endpoint |
| CIDR | Classless Inter-Domain Routing: 192.168.1.0/24 | Slash notation specifies network prefix length |
| Subnet mask | /24 = 255.255.255.0 = 16,777,216 hosts | Defines which part is network vs host |
| /8 | /8 = 255.0.0.0 — 16M hosts | Large /8 block — class A |
| /16 | /16 = 255.255.0.0 — 65,534 hosts | Medium /16 block — class B |
| /24 | /24 = 255.255.255.0 — 254 hosts | Common subnet — class C |
| /25 | /25 — 126 hosts — splits /24 in half | Half a /24 |
| /28 | /28 — 14 hosts — 16 IPs, 14 usable | Small subnet — AWS security groups default |
| /30 | /30 — 2 hosts — point-to-point links | Minimal subnet for router links |
| /32 | /32 — single host | Single IP address — host route |
| Network address | First IP in subnet — 192.168.1.0 in /24 | Not assignable to a host |
| Broadcast | Last IP in subnet — 192.168.1.255 in /24 | Sends to all hosts in subnet |
| Usable hosts | 2^(32-prefix) - 2 | Subtract network and broadcast addresses |
| NAT | Network Address Translation | Multiple private IPs share one public IP |
| PAT | Port Address Translation (NAPT) | Most common NAT — maps port numbers too |
| IPv6 | 128-bit address: 2001:db8::1 | Colon-hex notation — :: compresses zeros |
| IPv6 types | Global unicast, link-local fe80::/10, loopback ::1 | Public, local, loopback addresses |
| IPv6 notation | 2001:0db8:0000:0000:0000:0000:0000:0001 = 2001:db8::1 | Compress leading zeros and consecutive zero groups |
| Dual stack | System has both IPv4 and IPv6 addresses | Transition strategy — most modern systems |
| CIDR aggregation | 10.0.1.0/24 + 10.0.2.0/24 = 10.0.0.0/22 | Summarize routes — reduces routing table size |
# IP Addressing and Subnetting Reference
# ── CIDR Cheat Sheet ──────────────────────────────────────────
# Prefix Mask Hosts Subnets from /24
# /24 255.255.255.0 254 1
# /25 255.255.255.128 126 2
# /26 255.255.255.192 62 4
# /27 255.255.255.224 30 8
# /28 255.255.255.240 14 16
# /29 255.255.255.248 6 32
# /30 255.255.255.252 2 64
# /32 255.255.255.255 1 host -
# ── Subnet Calculator (Python) ────────────────────────────────
import ipaddress
def subnet_info(cidr: str):
net = ipaddress.IPv4Network(cidr, strict=False)
print(f"CIDR: {net}")
print(f"Network: {net.network_address}")
print(f"Broadcast: {net.broadcast_address}")
print(f"Netmask: {net.netmask}")
print(f"Wildcard: {net.hostmask}")
print(f"Hosts: {net.num_addresses - 2} usable")
print(f"First host: {list(net.hosts())[0]}")
print(f"Last host: {list(net.hosts())[-1]}")
print(f"Prefix len: /{net.prefixlen}")
return net
print("=== 192.168.1.0/24 ===")
net = subnet_info("192.168.1.0/24")
# Check if IP is in subnet
ip = ipaddress.IPv4Address("192.168.1.100")
print(f"\n{ip} in {net}: {ip in net}")
print(f"8.8.8.8 in {net}: {ipaddress.IPv4Address('8.8.8.8') in net}")
# Divide /24 into subnets
print("\n=== Split 192.168.1.0/24 into /26 subnets ===")
for i, subnet in enumerate(net.subnets(new_prefix=26)):
hosts = list(subnet.hosts())
print(f" Subnet {i+1}: {subnet} first={hosts[0]} last={hosts[-1]}")
# Private address check
for addr in ["10.0.0.1","172.16.5.1","192.168.1.1","8.8.8.8","203.0.113.1"]:
ip = ipaddress.IPv4Address(addr)
print(f" {addr:15} private={ip.is_private} loopback={ip.is_loopback}")
# IPv6
print("\n=== IPv6 ===")
ipv6 = ipaddress.IPv6Network("2001:db8::/32")
print(f"IPv6 network: {ipv6}")
print(f"Addresses: {ipv6.num_addresses:,}")
print(f"Link-local: {ipaddress.IPv6Address('fe80::1').is_link_local}")
print(f"Loopback: {ipaddress.IPv6Address('::1').is_loopback}")
# CIDR aggregation (supernetting)
nets = [ipaddress.IPv4Network(n) for n in ["10.0.0.0/24","10.0.1.0/24","10.0.2.0/24","10.0.3.0/24"]]
supernet = ipaddress.collapse_addresses(nets)
print("\nAggregated routes:", list(supernet))
# python3 ipaddr.py