Intuition The big picture (WHY subnetting exists)
An IP address is 32 bits that secretly answers two questions: "which network am I on?" and "which host am I on that network?". Subnetting is the act of moving the dividing line between the network part and the host part so we can carve one big block of addresses into many smaller, right-sized blocks.
WHY do we care? Because handing every department a full Class-A block wastes millions of addresses, and because routers only need to know networks , not individual hosts — fewer, well-organized networks = smaller routing tables + better security boundaries.
A 32-bit number, written as four octets (8-bit groups) in dotted-decimal, e.g. 192.168.10.130. Each octet ranges 0 0 0 –255 255 255 (since 2 8 = 256 2^8 = 256 2 8 = 256 ).
A 32-bit value where the leftmost contiguous 1s mark the network bits and the trailing 0s mark the host bits . The number of 1s is the prefix length , written /n (CIDR notation).
WHY contiguous? A router finds the network part by a bitwise AND of address & mask. For AND to cleanly "keep the left, zero the right," the 1s must be packed on the left — no gaps allowed.
Network address = IP AND Mask \text{Network address} = \text{IP} \;\text{AND}\; \text{Mask} Network address = IP AND Mask
Intuition Derivation from first principles (HOW we get
2 h − 2 2^h - 2 2 h − 2 )
With h h h host bits, every distinct combination of those bits is a potential host slot. The number of binary strings of length h h h is 2 h 2^h 2 h (each bit independently 0 or 1). Remove the 2 reserved patterns ⇒ 2 h − 2 2^h - 2 2 h − 2 assignable hosts.
Similarly, if you "steal" b b b of the host bits to label subnets, those b b b bits form 2 b 2^b 2 b distinct labels ⇒ 2 b 2^b 2 b subnets. The remaining h − b h-b h − b bits still address hosts.
Worked example Read a mask completely —
/26
n = 26 n=26 n = 26 , so h = 32 − 26 = 6 h = 32-26 = 6 h = 32 − 26 = 6 host bits. Why? 32 − n 32-n 32 − n is the leftover.
Hosts per subnet = 2 6 − 2 = 62 = 2^6 - 2 = 62 = 2 6 − 2 = 62 . Why? All combos minus network+broadcast.
Mask in binary: 26 ones then 6 zeros = 11111111.11111111.11111111.11000000 = 255.255.255.192. Why 192? Last octet has 2 ones: 128 + 64 = 192 128+64 = 192 128 + 64 = 192 .
Block size of the last varying octet = 256 − 192 = 64 = 256 - 192 = 64 = 256 − 192 = 64 . Why? Block size = how far apart consecutive subnet boundaries are = 2 h 2^h 2 h within that octet.
192.168.10.130/26, find its subnet
Step 1 — Block size = 256 − 192 = 64 256 - 192 = 64 256 − 192 = 64 . Why? The interesting octet is the 4th (mask 192). Subnets step in increments of 64.
Step 2 — List boundaries: 0, 64, 128, 192. Why? Multiples of the block size until ≥ 256.
Step 3 — Which block holds 130? 128 ≤ 130 < 192 128 \le 130 < 192 128 ≤ 130 < 192 , so subnet = 192.168.10.128. Why? The host lives in the block whose start it falls into.
Step 4 — Broadcast = next boundary − 1 = 192.168.10.191. Why? Broadcast is the all-1s host pattern, i.e. last address before the next subnet.
Step 5 — Host range = .129 to .190. Why? Everything strictly between network and broadcast.
VLSM means using different prefix lengths for different subnets of the same parent block, so each subnet is sized to its actual need instead of all being equal.
Intuition WHY VLSM beats fixed-size subnetting
Fixed subnetting forces every subnet to be the same size. If you split for the largest group, the small groups waste addresses; if you split for the smallest , the big group won't fit. VLSM lets a point-to-point link (needs 2 hosts) get a tiny /30, while a 100-host LAN gets a /25. Golden rule: allocate largest subnets first , so big blocks aren't fragmented into unusable pieces.
Worked example VLSM design from
192.168.1.0/24
Needs: A=100 hosts, B=50 hosts, C=25 hosts, D=2 hosts (a router link).
Step A (100 hosts): need 2 h − 2 ≥ 100 ⇒ h = 7 2^h-2 \ge 100 \Rightarrow h=7 2 h − 2 ≥ 100 ⇒ h = 7 (126 126 126 hosts). Prefix = 32 − 7 = / 25 =32-7=/25 = 32 − 7 = /25 . Block 192.168.1.0/25 → range .1–.126. Why h = 7 h=7 h = 7 ? 2 6 − 2 = 62 < 100 2^6-2=62<100 2 6 − 2 = 62 < 100 , 2 7 − 2 = 126 ≥ 100 2^7-2=126\ge100 2 7 − 2 = 126 ≥ 100 .
Step B (50 hosts): 2 6 − 2 = 62 ≥ 50 ⇒ h = 6 , / 26 2^6-2=62\ge50 \Rightarrow h=6, /26 2 6 − 2 = 62 ≥ 50 ⇒ h = 6 , /26 . Start at next free address .128 → 192.168.1.128/26, hosts .129–.190.
Step C (25 hosts): 2 5 − 2 = 30 ≥ 25 ⇒ / 27 2^5-2=30\ge25 \Rightarrow /27 2 5 − 2 = 30 ≥ 25 ⇒ /27 . Start .192 → 192.168.1.192/27, hosts .193–.222.
Step D (2 hosts): 2 2 − 2 = 2 ⇒ / 30 2^2-2=2 \Rightarrow /30 2 2 − 2 = 2 ⇒ /30 . Start .224 → 192.168.1.224/30, hosts .225–.226.
Why this order? Largest-first keeps each new block aligned to its own size boundary — no overlaps, no wasted gaps.
Common mistake Steel-manning the classic errors
(1) "Hosts per subnet is 2 h 2^h 2 h ." It feels right because 2 h 2^h 2 h is the count of bit patterns. But network + broadcast are reserved → subtract 2. Fix: 2 h − 2 2^h - 2 2 h − 2 .
(2) "More subnet bits give more hosts." Feels right because "more bits = more". But subnet bits are stolen from host bits; borrowing b b b bits multiplies subnets by 2 b 2^b 2 b and divides hosts. Fix: n + h = 32 n + h = 32 n + h = 32 always — it's a zero-sum trade.
(3) VLSM smallest-first. Feels efficient (use scraps first). But placing a /30 mid-block can leave the leftover space mis-aligned so a later /25 won't fit. Fix: largest-first .
(4) "Mask 255.255.255.192 means 192 hosts." Feels like 192 is the answer. But 192 is the mask octet, not a host count. Block size = 256 − 192 = 64 =256-192=64 = 256 − 192 = 64 , usable = 62 =62 = 62 .
Recall Feynman: explain to a 12-year-old
Imagine a big apartment building (the network) with a street number and lots of flat numbers (hosts). The IP address writes both together. The subnet mask is a marker pen line that says "everything left of this line is the building , everything right is the flat number ." Move the line right → more buildings but fewer flats per building. Two flat numbers are off-limits in every building: flat "0000" is the building's nameplate, and flat "1111" is the building loudspeaker (broadcast). VLSM is just smart building management: give big families big buildings and a couple sharing a hallway a tiny one, instead of identical buildings for everybody.
"N + H = 32, minus 2 for the host." And for VLSM: "BIG ones first, line up the doors." Block size mantra: "256 minus the mask octet."
How many bits is an IPv4 address and how is it grouped? 32 bits, four 8-bit octets in dotted-decimal.
What does a bitwise AND of IP and mask give you? The network (subnet) address.
Formula for usable hosts per subnet with h host bits? 2 h − 2 2^h - 2 2 h − 2 (minus network + broadcast).
Why subtract 2 from host count? All-0 host bits = network address; all-1 host bits = broadcast; neither is assignable.
For a /26 mask, how many host bits and usable hosts? 6 host bits,
2 6 − 2 = 62 2^6-2 = 62 2 6 − 2 = 62 hosts.
What is the last-octet mask value for /26? 192 (128+64).
How do you compute block size from a mask octet? 256 − mask octet (e.g. 256−192 = 64).
In 192.168.10.130/26, what is the subnet address? 192.168.10.128 (130 falls in the 128–191 block).
In 192.168.10.130/26, what is the broadcast address? 192.168.10.191 (next boundary 192 minus 1).
What does VLSM stand for and mean? Variable Length Subnet Masking — using different prefix lengths per subnet to size each to need.
What is VLSM's golden allocation rule? Allocate the largest subnets first.
What prefix do you need for a 2-host point-to-point link? /30 (
2 2 − 2 = 2 2^2-2 = 2 2 2 − 2 = 2 usable hosts).
Relationship between network bits n and host bits h? n + h = 32 (zero-sum trade).
Borrowing b host bits creates how many subnets?
IPv4 Addressing — the 32-bit structure subnetting operates on
CIDR and Supernetting — opposite move: merging networks, same prefix math
Routing Tables and Longest Prefix Match — why subnets shrink routing tables
Default Gateway and ARP — host uses mask to decide local vs remote delivery
Bitwise AND OR — the boolean operation behind network extraction
Network and Broadcast Addresses — the two reserved patterns
Intuition Hinglish mein samjho
Dekho, ek IPv4 address actually 32 bits ka hota hai, aur usme do cheezein chhupi hoti hain — "main kaunse network pe hoon" aur "us network pe main kaunsa host hoon". Subnet mask ek line khinchta hai: line ke left wale bits = network part, right wale bits = host part. Mask me jitne 1s, utne network bits (prefix /n), aur baaki 32−n host bits. Router network address nikalne ke liye IP aur mask ka bitwise AND karta hai — isiliye mask me 1s hamesha left side contiguous hote hain.
Host count ka formula simple hai: 2 h − 2 2^h - 2 2 h − 2 , jahan h h h = host bits. Minus 2 isliye kyunki all-0 host bits = network address (subnet ka naam) aur all-1 host bits = broadcast — ye dono kisi machine ko assign nahi kar sakte. Ek mast trick: block size = 256 − mask ka last octet . Jaise /26 me mask 255.255.255.192, block size = 256−192 = 64, to subnets 0, 64, 128, 192 pe shuru hote hain. Agar host .130 hai to wo 128–191 block me aata hai → network .128, broadcast .191, usable .129 se .190.
VLSM ka matlab hai har subnet ko alag size dena, uski zaroorat ke hisaab se. Fixed subnetting me sab equal size — jo bada group hai usko fit nahi hota ya chhote groups me addresses waste. VLSM me 100-host LAN ko /25 do, 2-host router link ko /30. Golden rule: sabse bade subnet pehle allocate karo , taaki blocks theek se align rahein aur baad me bade subnet ke liye jagah bache. Yaad rakho: n + h = 32 n + h = 32 n + h = 32 — network bits badhao to host bits ghatega, ye ek zero-sum trade hai.