IP Addressing & Subnetting

A deep dive into IPv4 structure, addressing classes, and the logic of subnetting.

IPv4 Address Format

The IPv4 address is a unique 32-bit identifier for a host or router interface.

Dotted Decimal Notation

192
11000000
1st Octet
.
168
10101000
2nd Octet
.
43
00101011
3rd Octet
.
241
11110001
4th Octet
Total = 32 Bits (4 Bytes) | Each octet = 8 Bits (1 Byte)
عنوان الـ IP بيتكون من 32 بت، متقسمين لـ 4 مجموعات (كل واحدة اسمها Octet). كل Octet فيه 8 بت، وبنكتبهم بالأرقام العادية (Decimal) عشان نسهل قراءتهم.
IP Addressing Classes (Deep Dive)
Class Range (1st Octet) Structure Max Hosts Target User
Class A 1 - 126 N . H . H . H 16,777,214 Governments & Giant Corps
Class B 128 - 191 N . N . H . H 65,534 Medium to Large Companies
Class C 192 - 223 N . N . N . H 254 Small Groups & Home LANs

The "Missing" 127

Address 127.0.0.1 is reserved for Loopback (diagnostics). It points back to your own machine.

ليه كلاس A بيقف عند 126؟ عشان 127 متجوزة للـ localhost (جهازك نفسه).

Multicasting (Class D)

Used for streaming (Audio/Video). Instead of 1-to-1 (Unicast), it is 1-to-Many.

الـ Multicast يعني ببعت داتا واحدة لكل اللي مشتركين في "قناة" معينة (زي البث المباشر).
Subnetting Mechanics

How many Hosts can we have? (The Power of 2)

The separation between Network and Host is defined by the Subnet Mask. If we have 16 bits for Hosts, how many IPs is that?

Network Portion
172 . 16
16 Bits
|
Host Portion
0 . 0
16 Bits (N)
Formula: 2N - 2
216 - 2 = 65,534 Hosts

⚠️ ليه بنطرح 2؟ (Reserved Addresses)

  • الـ 0: محجوز لعنوان الشبكة نفسها (Network Address).
  • الـ 255 (أو آخر رقم): محجوز للـ Broadcast (عشان تبعت رسالة لكل الناس في الشبكة).

CIDR: The Solution to IP Exhaustion

Old "Classful" addressing was wasteful. If you needed 300 hosts, Class C was too small (254) and Class B was too big (65k).

CIDR (Classless Inter-Domain Routing) allows us to define the network boundary at any bit using /Notation.

// Subnet Mask Breakdown for /26
Binary: 11111111.11111111.11111111.11000000
Bits:    8 bits + 8 bits + 8 bits + 2 bits = 26
Decimal: 255.255.255.192
Practical Subnetting Tutorial
SUB-NETS

Subnets (الشبكات)

2y

y = bits borrowed from Host portion.

HOSTS

Hosts (الأجهزة)

2x - 2

x = remaining Host bits after borrowing.

Solving a Subnetting Problem

1
Identify the default class mask:

For 192.168.43.0, it's Class C (Default /24).

2
Calculate Borrowed Bits (y):

We have /26. Borrowed bits = 26 - 24 = 2 bits.

3
Build the Network Ranges:

Increment = 256 - 192 = 64.

Net ID First Host Last Host Broadcast
.0 .1 .62 .63
.64 .65 .126 .127
.128 .129 .190 .191
.192 .193 .254 .255
أول رقم دايماً هو Network ID (ممنوع لجهاز ياخده)، وآخر رقم هو Broadcast (ممنوع لجهاز ياخده). عشان كدة ديماً بنطرح 2 من عدد الأجهزة المتاحة.
Private IP Ranges

Private IP addresses are used for internal networks and are not routable on the public internet.

Class A: 10.0.0.0 → 10.255.255.255
Class B: 172.16.0.0 → 172.31.255.255
Class C: 192.168.0.0 → 192.168.255.255
ليه فيه Private IPs؟ عشان نقدر نستخدم عناوين IP ملايين المرات جوه الشركات والبيوت من غير ما نخلص العناوين المتاحة في العالم، وبنحتاج راوتر (NAT) عشان يخرجنا للنت الحقيقي.

Practice Arena 🎯

1. An IPv4 address is divided into which two primary identifiers?
2. What is the total length of an IPv4 address in bits?