Chapter 1: Networking Fundamentals
1.4 IPv4 in detail
This is the most important section of the chapter, so dhyan do. Once IPv4 is clear, CIDR and subnets in AWS will feel very natural.
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).
Worked subnetting example
Chala, aata ek example karuya together — 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 becomes easy only with practice, not by reading. Do five problems daily for one week using the block-size trick (256 − mask octet), and verify each answer with ipcalc. Interviewers love asking you to split a /24 into four subnets on a whiteboard — and you will be ready.
Ravindra Bagale's Tip – मराठी
Subnetting फक्त वाचून नाही, तर practice करूनच सोपं होतं. एक आठवडा रोज पाच प्रश्न block-size trick (256 − mask octet) वापरून सोडवा आणि प्रत्येक उत्तर ipcalc ने तपासा. Interview मध्ये whiteboard वर /24 चे चार subnets करून दाखवा, हा प्रश्न interviewers ना खूप आवडतो — तेव्हा तुम्ही तयार असाल.
Ravindra Bagale's Tip – हिंदी
Subnetting सिर्फ़ पढ़ने से नहीं, practice से ही आसान होता है. एक हफ़्ते तक रोज़ पाँच सवाल block-size trick (256 − mask octet) से हल करो और हर जवाब ipcalc से चेक करो. Interview में whiteboard पर /24 को चार subnets में बाँटना — यह सवाल interviewers को बहुत पसंद है, और तब तुम तैयार रहोगे.