4.3.9 · Coding › Computer Networks
Intuition Big picture (WHY subnetting exist karta hai)
Ek IP address 32 bits ka hota hai jo secretly do sawaalon ka jawab deta hai: "main kaun se network par hoon?" aur "main us network par kaun sa host hoon?". Subnetting woh kaam hai jisme hum network part aur host part ke beech ki dividing line ko move karte hain taaki ek bade address block ko kai chhote, sahi size ke blocks mein kaat sakein.
WHY care karein? Kyunki har department ko ek poora Class-A block dena lakhon addresses waste karta hai, aur kyunki routers ko sirf networks jaanna hota hai, individual hosts nahi — kam, well-organized networks = chhoti routing tables + behtar security boundaries.
Ek 32-bit number, jo four octets (8-bit groups) mein dotted-decimal mein likha jaata hai, e.g. 192.168.10.130. Har octet 0 –255 ke beech hota hai (kyunki 2 8 = 256 ).
Ek 32-bit value jisme sabse baayein contiguous 1s network bits mark karte hain aur trailing 0s host bits mark karte hain . 1s ki count prefix length hai, jo /n (CIDR notation) mein likhi jaati hai.
WHY contiguous? Router network part ko bitwise AND of address & mask se dhundta hai. AND ke liye "left part rakhna, right part zero karna" cleanly kaam kare, 1s ko left mein pack hona chahiye — beech mein koi gap nahi.
Network address = IP AND Mask
Intuition First principles se derivation (HOW hum
2 h − 2 paate hain)
h host bits ke saath, un bits ke har distinct combination ek potential host slot hai. Length h ke binary strings ki count 2 h hoti hai (har bit independently 0 ya 1). 2 reserved patterns hatao ⇒ 2 h − 2 assignable hosts.
Isi tarah, agar tum subnets label karne ke liye b host bits "churaate" ho, woh b bits 2 b distinct labels banate hain ⇒ 2 b subnets. Baaki h − b bits abhi bhi hosts address karte hain.
Worked example Ek mask poora padho —
/26
n = 26 , toh h = 32 − 26 = 6 host bits. Why? 32 − n bacha hua hai.
Hosts per subnet = 2 6 − 2 = 62 . Why? Saare combos minus network+broadcast.
Mask binary mein: 26 ones phir 6 zeros = 11111111.11111111.11111111.11000000 = 255.255.255.192. Why 192? Last octet mein 2 ones hain: 128 + 64 = 192 .
Last varying octet ka Block size = 256 − 192 = 64 . Why? Block size = consecutive subnet boundaries ke beech ka faraq = us octet mein 2 h .
192.168.10.130/26 diya hai, iska subnet dhundo
Step 1 — Block size = 256 − 192 = 64 . Why? Interesting octet 4th hai (mask 192). Subnets 64 ke increments mein chalte hain.
Step 2 — Boundaries list karo: 0, 64, 128, 192. Why? Block size ke multiples jab tak ≥ 256 na ho jaaye.
Step 3 — 130 kis block mein hai? 128 ≤ 130 < 192 , toh subnet = 192.168.10.128. Why? Host us block mein hai jiske start mein woh aata hai.
Step 4 — Broadcast = next boundary − 1 = 192.168.10.191. Why? Broadcast all-1s host pattern hai, yaani next subnet se pehle ka last address.
Step 5 — Host range = .129 se .190. Why? Network aur broadcast ke beech ka sabkuch strictly.
VLSM ka matlab hai ek hi parent block ke alag-alag subnets ke liye alag-alag prefix lengths use karna , taaki har subnet sab barabar hone ki jagah apni actual zaroorat ke hisaab se size ho.
Intuition WHY VLSM fixed-size subnetting se behtar hai
Fixed subnetting mein har subnet same size ka hona padta hai. Agar sabse bade group ke liye split karo, chhote groups addresses waste karte hain; agar sabse chhote ke liye split karo, bada group fit nahi hoga. VLSM ek point-to-point link (2 hosts chahiye) ko tiny /30 lene deta hai, jabki 100-host LAN ko /25 milta hai. Golden rule: pehle sabse bade subnets allocate karo , taaki bade blocks unusable pieces mein fragment na hon.
192.168.1.0/24 se VLSM design
Zaroorat: A=100 hosts, B=50 hosts, C=25 hosts, D=2 hosts (ek router link).
Step A (100 hosts): chahiye 2 h − 2 ≥ 100 ⇒ h = 7 (126 hosts). Prefix = 32 − 7 = /25 . Block 192.168.1.0/25 → range .1–.126. Why h = 7 ? 2 6 − 2 = 62 < 100 , 2 7 − 2 = 126 ≥ 100 .
Step B (50 hosts): 2 6 − 2 = 62 ≥ 50 ⇒ h = 6 , /26 . Agli free address .128 se shuru → 192.168.1.128/26, hosts .129–.190.
Step C (25 hosts): 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 . Start .224 → 192.168.1.224/30, hosts .225–.226.
Why yeh order? Largest-first rakhne se har naya block apni size boundary par aligned rehta hai — koi overlap nahi, koi wasted gap nahi.
Common mistake Classic errors ko steel-man karna
(1) "Hosts per subnet 2 h hai." Sahi lagta hai kyunki 2 h bit patterns ki count hai. Lekin network + broadcast reserved hain → 2 ghatao. Fix: 2 h − 2 .
(2) "Zyada subnet bits se zyada hosts milte hain." Sahi lagta hai kyunki "more bits = more". Lekin subnet bits host bits se churi jaati hain ; b bits borrow karna subnets ko 2 b se multiply karta hai aur hosts ko divide karta hai. Fix: n + h = 32 hamesha — yeh zero-sum trade hai.
(3) VLSM smallest-first. Efficient lagta hai (pehle scraps use karo). Lekin /30 ko block ke beech mein rakhne se bacha hua space mis-aligned ho sakta hai aur baad mein /25 fit nahi hoga. Fix: largest-first .
(4) "Mask 255.255.255.192 ka matlab 192 hosts hai." Lagta hai 192 answer hai. Lekin 192 mask octet hai, host count nahi. Block size = 256 − 192 = 64 , usable = 62 .
Recall Feynman: ek 12-saal ke bacche ko samjhao
Socho ek bada apartment building (network) hai jisme ek street number aur bahut saare flat numbers (hosts) hain. IP address dono ek saath likhta hai. Subnet mask ek marker pen ki line hai jo kehti hai "is line ke left mein sab building hai, right mein flat number hai." Line ko right mein kheencho → zyada buildings lekin har building mein kam flats. Har building mein do flat numbers off-limits hain: flat "0000" building ka nameplate hai, aur flat "1111" building ka loudspeaker hai (broadcast). VLSM bas smart building management hai: bade parivaron ko bade buildings do aur ek hallway share karne waale couple ko tiny wala, sabko identical buildings dene ki jagah.
"N + H = 32, minus 2 for the host." Aur VLSM ke liye: "BIG ones first, line up the doors." Block size mantra: "256 minus the mask octet."
IPv4 address mein kitne bits hote hain aur kaise group kiya jaata hai? 32 bits, four 8-bit octets dotted-decimal mein.
IP aur mask ka bitwise AND kya deta hai? Network (subnet) address.
h host bits ke saath usable hosts per subnet ka formula? 2 h − 2 (minus network + broadcast).
Host count se 2 kyun ghatate hain? All-0 host bits = network address; all-1 host bits = broadcast; dono assignable nahi hain.
/26 mask ke liye kitne host bits aur usable hosts? 6 host bits, 2 6 − 2 = 62 hosts.
/26 ke liye last-octet mask value kya hai? 192 (128+64).
Mask octet se block size kaise calculate karte hain? 256 − mask octet (e.g. 256−192 = 64).
192.168.10.130/26 mein subnet address kya hai? 192.168.10.128 (130, 128–191 block mein aata hai).
192.168.10.130/26 mein broadcast address kya hai? 192.168.10.191 (next boundary 192 minus 1).
VLSM ka full form aur matlab kya hai? Variable Length Subnet Masking — har subnet ko uski zaroorat ke hisaab se size karne ke liye alag-alag prefix lengths use karna.
VLSM ka golden allocation rule kya hai? Pehle sabse bade subnets allocate karo.
2-host point-to-point link ke liye kaunsa prefix chahiye? /30 (2 2 − 2 = 2 usable hosts).
Network bits n aur host bits h ka relationship kya hai? n + h = 32 (zero-sum trade).
b host bits borrow karne se kitne subnets bante hain? 2 b subnets.
IPv4 Addressing — woh 32-bit structure jis par subnetting operate karta hai
CIDR and Supernetting — ulta kaam: networks merge karna, same prefix math
Routing Tables and Longest Prefix Match — subnets routing tables kyun chhoti karte hain
Default Gateway and ARP — host mask use karke decide karta hai local vs remote delivery
Bitwise AND OR — network extraction ke peeche ka boolean operation
Network and Broadcast Addresses — do reserved patterns