From binary fundamentals to rapid subnet calculations — everything you need to design and debug IP networks.
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.
| Bit Position | Power of 2 | Decimal Value |
|---|---|---|
| 1st (MSB) | 2^7 | 128 |
| 2nd | 2^6 | 64 |
| 3rd | 2^5 | 32 |
| 4th | 2^4 | 16 |
| 5th | 2^3 | 8 |
| 6th | 2^2 | 4 |
| 7th | 2^1 | 2 |
| 8th (LSB) | 2^0 | 1 |
Classful addressing divides IPv4 space into five classes based on the leading bits of the first octet.
| Class | Leading Bits | First Octet Range | Default Mask | Network/Host Split | Use Case |
|---|---|---|---|---|---|
| A | 0xxx xxxx | 1 – 126 | /8 (255.0.0.0) | Net.Host.Host.Host | Large organizations |
| B | 10xx xxxx | 128 – 191 | /16 (255.255.0.0) | Net.Net.Host.Host | Medium organizations |
| C | 110x xxxx | 192 – 223 | /24 (255.255.255.0) | Net.Net.Net.Host | Small networks |
| D | 1110 xxxx | 224 – 239 | — | Multicast | Multicast groups |
| E | 1111 xxxx | 240 – 255 | — | Reserved | Research/experimental |
CIDR replaced classful addressing in 1993. It uses a /prefix-length suffix to indicate how many bits are fixed as the network portion.
| CIDR | Subnet Mask | Broadcast Mask | Total IPs | Usable Hosts |
|---|---|---|---|---|
| /8 | 255.0.0.0 | 11111111.00000000.00000000.00000000 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 11111111.11111111.00000000.00000000 | 65,536 | 65,534 |
| /24 | 255.255.255.0 | 11111111.11111111.11111111.00000000 | 256 | 254 |
| /25 | 255.255.255.128 | — | 128 | 126 |
| /26 | 255.255.255.192 | — | 64 | 62 |
| /27 | 255.255.255.224 | — | 32 | 30 |
| /28 | 255.255.255.240 | — | 16 | 14 |
| /29 | 255.255.255.248 | — | 8 | 6 |
| /30 | 255.255.255.252 | — | 4 | 2 |
| Prefix | Interesting Octet Value | Increment/Borrow |
|---|---|---|
| /24 | 255.255.255.0 | — (boundary) |
| /25 | 255.255.255.128 | 128 |
| /26 | 255.255.255.192 | 64 |
| /27 | 255.255.255.224 | 32 |
| /28 | 255.255.255.240 | 16 |
| /29 | 255.255.255.248 | 8 |
| /30 | 255.255.255.252 | 4 |
Given: 192.168.10.0/26 — Find network address, broadcast, usable range, and host count.
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.
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
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
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
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 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.
| Feature | IPv4 | IPv6 |
|---|---|---|
| Address size | 32 bits (4.3 billion) | 128 bits (~3.4×10^38) |
| Notation | Dotted decimal | Hex colon-separated |
| Configuration | Manual or DHCP | SLAAC (stateless) or DHCPv6 |
| NAT | Necessary due to scarcity | Generally unnecessary |
| Headers | 20+ bytes, options variable | 40 bytes fixed, extensible |
| Security | Optional (IPsec added later) | Designed with IPsec in mind |
| Fragmentation | Routers can fragment | Only source can fragment |
| Range | Class | CIDR | Notes |
|---|---|---|---|
| 10.0.0.0 – 10.255.255.255 | A | /8 | Single /8 — largest private block |
| 172.16.0.0 – 172.31.255.255 | B | /12–/16 | 16 contiguous /12 blocks |
| 192.168.0.0 – 192.168.255.255 | C | /16 | 256 contiguous /24 networks — most common |
| 100.64.0.0 – 100.127.255.255 | — | /10 | Carrier-grade NAT (CGNAT, RFC 6598) |
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 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).