AiTechWorlds
AiTechWorlds
Every house in a city has an address that works at multiple scales: House Number → Street → City → ZIP Code → Country. Each part narrows the location from country-level down to a specific door.
IP addresses work exactly the same way. An IP address has two parts:
A subnet is like dividing a large city into smaller neighborhoods. Instead of one giant "Dhaka" network, you create "Dhanmondi," "Gulshan," "Mirpur" — smaller, manageable zones. Routers deliver to the right neighborhood, and local switches deliver to the specific house.
Every device on a network needs a unique identifier — its IP address. IPv4 addresses are 32-bit binary numbers, displayed as four decimal numbers (octets) separated by dots.
Example: 192.168.1.100
192 . 168 . 1 . 100
11000000 10101000 00000001 01100100
Each octet is 8 bits. 8 bits can represent 0–255 in decimal. So every octet in an IP address is between 0 and 255.
Total IPv4 address space: 2^32 = 4,294,967,296 addresses (~4.3 billion)
This seemed like an enormous number in 1981. Today, with billions of devices, we have run out — which is why IPv6 (128-bit, ~340 undecillion addresses) was developed.
Understanding binary is essential for subnetting. Each bit position has a value:
Bit position: 128 64 32 16 8 4 2 1
--- -- -- -- - - - -
Example (192): 1 1 0 0 0 0 0 0
Calculation: 128 + 64 = 192
Example (168): 1 0 1 0 1 0 0 0
128 + 0+ 32 + 0 + 8 + 0 +0+0 = 168
Quick conversion trick: Remember 128, 64, 32, 16, 8, 4, 2, 1. Work left to right, subtracting as you go.
Before CIDR, IP addresses were divided into fixed classes. While classful routing is obsolete, you will still see these terms:
| Class | First Bits | Range | Default Mask | Networks | Hosts/Network | Originally For |
|---|---|---|---|---|---|---|
| A | 0xxx | 1.0.0.0 – 126.x.x.x | /8 (255.0.0.0) | 126 | 16,777,214 | Large corporations, governments |
| B | 10xx | 128.0.0.0 – 191.255.x.x | /16 (255.255.0.0) | 16,384 | 65,534 | Medium organizations |
| C | 110x | 192.0.0.0 – 223.255.255.x | /24 (255.255.255.0) | 2,097,152 | 254 | Small organizations |
| D | 1110 | 224.0.0.0 – 239.x.x.x | N/A | Multicast | Multicast | Multicast groups |
| E | 1111 | 240.0.0.0 – 255.x.x.x | N/A | Reserved | Reserved | Experimental |
Class A gave huge organizations millions of addresses (wasteful). Class C gave small organizations only 254 (often not enough). CIDR solved this by allowing any prefix length.
The subnet mask tells devices which portion of an IP address is the network identifier and which portion identifies the host.
IP Address: 192 . 168 . 1 . 100
11000000 10101000 00000001 01100100
Subnet Mask: 255 . 255 . 255 . 0
11111111 11111111 11111111 00000000
|_________________________| |_____|
Network Portion Host Portion
The rule: Where the subnet mask has a 1, that bit belongs to the network. Where it has a 0, that bit is a host bit.
Performing a bitwise AND between the IP address and subnet mask gives you the network address:
IP: 11000000.10101000.00000001.01100100
Mask: 11111111.11111111.11111111.00000000
AND: 11000000.10101000.00000001.00000000 = 192.168.1.0 (Network Address)
CIDR (Classless Inter-Domain Routing) notation expresses the subnet mask as a count of network bits after a /.
192.168.1.0/24 means the first 24 bits are the network portion/24 = 255.255.255.0 (24 ones followed by 8 zeros)/16 = 255.255.0.0 (16 ones followed by 16 zeros)/8 = 255.0.0.0 (8 ones followed by 24 zeros)Given: Network 192.168.1.0/24
Find: Network address, broadcast address, first usable host, last usable host, total usable hosts
Step 1: Identify the host bits
Step 2: Calculate total addresses
Step 3: Calculate usable hosts
Step 4: Identify key addresses
Network Address: 192.168.1.0 (all host bits = 0)
First Usable Host: 192.168.1.1
Last Usable Host: 192.168.1.254
Broadcast Address: 192.168.1.255 (all host bits = 1)
Why subtract 2?
Not all IP addresses are publicly routable on the internet. RFC 1918 defines three ranges reserved for private use. These addresses can be used inside any organization without registration — but routers on the public internet will not forward them.
| Range | CIDR | Addresses | Common Use |
|---|---|---|---|
| 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | 16,777,216 | Large enterprises |
| 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | 1,048,576 | Medium organizations |
| 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | 65,536 | Home and small office networks |
Your home router almost certainly assigns 192.168.x.x addresses. Your ISP uses NAT (Network Address Translation) to map all your private addresses to one public IP — allowing thousands of homes to share the public address space.
Other reserved ranges:
127.0.0.0/8 — Loopback (127.0.0.1 = "this device itself," used for testing)169.254.0.0/16 — APIPA (Automatic Private IP Addressing — assigned when DHCP fails)| CIDR | Subnet Mask | Total Addresses | Usable Hosts | Typical Use Case |
|---|---|---|---|---|
| /30 | 255.255.255.252 | 4 | 2 | Point-to-point router links |
| /29 | 255.255.255.248 | 8 | 6 | Small server groups |
| /28 | 255.255.255.240 | 16 | 14 | Very small office |
| /27 | 255.255.255.224 | 32 | 30 | Small office |
| /26 | 255.255.255.192 | 64 | 62 | Medium office floor |
| /25 | 255.255.255.128 | 128 | 126 | Large office floor |
| /24 | 255.255.255.0 | 256 | 254 | Standard small network |
| /23 | 255.255.254.0 | 512 | 510 | Medium network |
| /22 | 255.255.252.0 | 1,024 | 1,022 | Large branch office |
| /16 | 255.255.0.0 | 65,536 | 65,534 | Large campus |
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 | Very large enterprise |
A small company has 3 departments: Engineering (50 people), Sales (25 people), HR (10 people). They have been assigned 192.168.10.0/24.
Rather than giving all 254 addresses to everyone on one flat network (security risk — all traffic is visible), they subnet:
Engineering: 192.168.10.0/26 → 62 usable hosts (covers 50 people + growth)
Sales: 192.168.10.64/27 → 30 usable hosts (covers 25 people)
HR: 192.168.10.96/28 → 14 usable hosts (covers 10 people)
Management: 192.168.10.112/30 → 2 usable hosts (router interconnect)
Each department is now isolated by subnet. Traffic between departments must go through the router, where firewall rules control access. HR data cannot be seen from the Engineering subnet. This is the real power of subnetting — not just address efficiency, but network segmentation for security.
Get this course's notes on Telegram!
Free cheat sheets, summaries & practice exercises