Chapter 1: Networking Fundamentals
1.4 IPv4 in detail
Friends, pay attention. This is the most important section of the chapter, so focus completely. Once IPv4 is clear, CIDR and subnets in AWS will feel very natural. Don't worry – take a pen and paper and do the calculations with me.
मित्रांनो, लक्ष द्या. हा या चॅप्टरमधला सगळ्यात इम्पॉर्टंट सेक्शन आहे, म्हणून एकदम लक्ष द्या. IPv4 क्लिअर झालं की AWS मधले CIDR आणि सबनेट्स एकदम सोपे वाटतील. घाबरू नका – पेन आणि कागद घ्या, आणि माझ्यासोबत हिशोब करा.
दोस्तों, ध्यान दो. ये इस चैप्टर का सबसे इम्पॉर्टेंट सेक्शन है, इसलिए पूरा ध्यान दो. IPv4 क्लियर हो गया तो AWS में CIDR और सबनेट्स बिल्कुल आसान लगेंगे. घबराओ मत – पेन और कागज़ लो, और मेरे साथ हिसाब करो.
Structure
An IPv4 address is 32 bits, written as four octets (8 bits each) in dotted-decimal form. Each octet ranges from 0 to 255.
192 . 168 . 1 . 10
11000000 10101000 00000001 00001010
|<-8 bits->|
|<---------------- 32 bits ---------------->|
Total possible IPv4 addresses = 2^32 ≈ 4.3 billion — not enough for today's world of phones, laptops and IoT devices. That is the main reason for NAT, private IPs and IPv6.
Every IPv4 address has two parts:
- Network portion — identifies the network (like the street name).
- Host portion — identifies the device on that network (like the house number).
The subnet mask tells which bits are network and which are host. Example: 255.255.255.0 means the first 24 bits are network bits.
Classful addressing (historical but asked in exams)
| Class | First octet range | Leading bits | Default mask | Networks / Hosts per network | Use |
|---|---|---|---|---|---|
| A | 1 – 126 | 0 | 255.0.0.0 (/8) | 126 / ~16.7 million | Very large networks |
| B | 128 – 191 | 10 | 255.255.0.0 (/16) | 16,384 / 65,534 | Medium networks |
| C | 192 – 223 | 110 | 255.255.255.0 (/24) | ~2 million / 254 | Small networks |
| D | 224 – 239 | 1110 | — | — | Multicast |
| E | 240 – 255 | 1111 | — | — | Experimental / reserved |
What about 127?
127.0.0.0/8 is reserved for loopback. 127.0.0.1 (also called localhost) always means "this same machine". When an app listens on 127.0.0.1:3000, it is reachable only from the server itself — that is exactly what we want behind a reverse proxy.
CIDR (Classless Inter-Domain Routing)
Classes waste addresses (a company needing 500 hosts would get a whole Class B of 65,534). CIDR replaced classes. We write the address followed by /n, where n = number of network bits.
| CIDR | Subnet mask | Total addresses | Usable hosts (traditional) | Usable in AWS subnet |
|---|---|---|---|---|
| /16 | 255.255.0.0 | 65,536 | 65,534 | 65,531 |
| /20 | 255.255.240.0 | 4,096 | 4,094 | 4,091 |
| /24 | 255.255.255.0 | 256 | 254 | 251 |
| /25 | 255.255.255.128 | 128 | 126 | 123 |
| /26 | 255.255.255.192 | 64 | 62 | 59 |
| /27 | 255.255.255.224 | 32 | 30 | 27 |
| /28 | 255.255.255.240 | 16 | 14 | 11 |
| /32 | 255.255.255.255 | 1 | single host | — |
Formula: total addresses = 2^(32 − n), usable hosts = 2^(32 − n) − 2 (network address and broadcast address are reserved).
AWS reserves 5 addresses
In every AWS subnet the first four and the last IP are reserved: network address, VPC router (.1), DNS (.2), future use (.3) and the last (broadcast) address. So a /24 subnet gives 251 usable IPs. The smallest subnet AWS allows is /28 and the largest VPC is /16.
0.0.0.0/0 means "every IPv4 address" — you will see it in security groups ("anywhere") and route tables (default route).
Suppose the Mauli Dairy office Wi-Fi network is 192.168.1.0/24 – that means the first 24 bits belong to the network and the last 8 bits to the devices, giving 254 usable hosts. If the same block were an AWS subnet, you would get 251 usable IPs, because AWS reserves 5 addresses in every subnet.
Mauli Dairy च्या ऑफिस Wi-Fi चं नेटवर्क 192.168.1.0/24 आहे असं समजा – म्हणजे पहिले 24 बिट्स नेटवर्कचे आणि शेवटचे 8 बिट्स डिव्हाइसेसचे, म्हणजे 254 usable होस्ट्स. तेच जर AWS सबनेट असतं तर 251 usable IPs मिळतील, कारण AWS प्रत्येक सबनेटमध्ये 5 ॲड्रेसेस राखून ठेवतो.
मान लो Mauli Dairy के ऑफ़िस Wi-Fi का नेटवर्क 192.168.1.0/24 है – मतलब पहले 24 बिट्स नेटवर्क के और आख़िरी 8 बिट्स डिवाइसेस के, यानी 254 usable होस्ट्स. वही अगर AWS सबनेट होता तो 251 usable IPs मिलेंगे, क्योंकि AWS हर सबनेट में 5 ऐड्रेसेस रिज़र्व रखता है.
Worked subnetting example
Come on, let's work through an example together now – take a pen and paper, don't just read.
चला, आता एक उदाहरण एकत्र करूया – पेन आणि कागद घ्या, फक्त वाचू नका.
चलो, अब एक उदाहरण साथ में करते हैं – पेन और कागज़ लो, सिर्फ़ पढ़ो मत.
Problem: Your college lab is given the network 192.168.10.0/24. Divide it into 4 equal subnets for four labs. Find each subnet's network address, usable range and broadcast address.
Step 1 — borrow bits. 4 subnets need 2 extra bits (2² = 4). New prefix = 24 + 2 = /26.
Step 2 — block size. Addresses per subnet = 2^(32−26) = 64. Mask = 255.255.255.192.
Step 3 — list subnets (increase the last octet in steps of 64):
| Subnet | Network address | First usable | Last usable | Broadcast | Usable hosts |
|---|---|---|---|---|---|
| Lab 1 | 192.168.10.0/26 | 192.168.10.1 | 192.168.10.62 | 192.168.10.63 | 62 |
| Lab 2 | 192.168.10.64/26 | 192.168.10.65 | 192.168.10.126 | 192.168.10.127 | 62 |
| Lab 3 | 192.168.10.128/26 | 192.168.10.129 | 192.168.10.190 | 192.168.10.191 | 62 |
| Lab 4 | 192.168.10.192/26 | 192.168.10.193 | 192.168.10.254 | 192.168.10.255 | 62 |
Step 4 — check with binary. Host 192.168.10.100: last octet 100 = 01100100. The first two bits (01) are the subnet bits → subnet 1 (counting from 0) → it belongs to Lab 2 (192.168.10.64/26).
Quick trick for block size
Block size = 256 − (last non-255 octet of the mask). For /26 the mask is 255.255.255.192, so block = 256 − 192 = 64. Subnets start at 0, 64, 128, 192.
AWS example: A VPC 10.0.0.0/16 is commonly split into subnets 10.0.1.0/24 (public, AZ-a), 10.0.2.0/24 (public, AZ-b), 10.0.11.0/24 (private, AZ-a) and 10.0.12.0/24 (private, AZ-b).
You can check subnet maths on Linux with the ipcalc tool (package ipcalc):
ipcalc 192.168.10.64/26
Ravindra Bagale's Tip
Subnetting comes with practice, not with reading. For one week, solve five problems every day – using the block-size trick (256 − mask octet) – and check every answer with ipcalc. In interviews you are very often asked to split a /24 into four subnets on the whiteboard – you will be ready.
Ravindra Bagale's Tip – मराठी
Subnetting वाचून नाही, practice ने येतं. एक आठवडा रोज पाच problems सोडवा – block-size trick (256 − mask octet) वापरून – आणि प्रत्येक उत्तर ipcalc ने check करा. Interview मध्ये whiteboard वर /24 चे चार subnets करायला खूप वेळा विचारतात – तुम्ही तयार असाल.
Ravindra Bagale's Tip – हिंदी
Subnetting पढ़कर नहीं, practice से आता है. एक हफ़्ता रोज़ पाँच problems हल करो – block-size trick (256 − mask octet) इस्तेमाल करके – और हर जवाब ipcalc से check करो. Interview में whiteboard पर /24 के चार subnets बनाने को बहुत बार कहते हैं – आप तैयार रहोगे.
Ravindra Bagale's Tip
Many students say a /26 has 64 usable hosts. Wrong! 64 is the total number of addresses – subtract the network and broadcast addresses and you get 62, and in an AWS subnet 59. Remember the formula: 2^(32 − n), then −2 (−5 in AWS).
Ravindra Bagale's Tip – मराठी
बरेच students /26 मध्ये 64 usable hosts सांगतात. चूक! 64 हे total addresses आहेत – network आणि broadcast वजा केले की 62, आणि AWS subnet मध्ये 59. Formula लक्षात ठेवा: 2^(32 − n), मग −2 (AWS मध्ये −5).
Ravindra Bagale's Tip – हिंदी
बहुत से students /26 में 64 usable hosts बताते हैं. गलत! 64 total addresses हैं – network और broadcast घटाओ तो 62, और AWS subnet में 59. Formula याद रखो: 2^(32 − n), फिर −2 (AWS में −5).
Lab
Chala, 10.0.0.0/24 che 4 equal subnets kara: navin prefix, block size, pratyek subnet cha network address, usable range aani broadcast liha. Mag ipcalc 10.0.0.64/26 chalvun tumchya dusrya subnet che uttar match kara.
Got it? IPv4 = 32 bits, CIDR /n = network bits, and the block-size trick – once these three things are solid, subnetting will feel easy. Now let's move on to IPv6.
समजलं का? IPv4 = 32 बिट्स, CIDR /n = नेटवर्क बिट्स, आणि ब्लॉक-साइझ ट्रिक – या तीन गोष्टी पक्क्या झाल्या की सबनेटिंग सोपं वाटेल. आता पुढे जाऊया IPv6 कडे.
समझ आया? IPv4 = 32 बिट्स, CIDR /n = नेटवर्क बिट्स, और ब्लॉक-साइज़ ट्रिक – ये तीन चीज़ें पक्की हो गईं तो सबनेटिंग आसान लगेगा. अब आगे चलते हैं IPv6 की तरफ़.