#FinalExam very important
IP Addressing Basics
- IP Addressing is Logical Addressing
- Works on Network Layer (Layer 3)
- Two versions of Addressing Scheme:
- IPv4 – 32 bit addressing
- IPv6 – 128 bit addressing
ลองเช็คดูได้
ifconfig
IPv4
- Bit representation: A value that represents 0's or 1's (Binary)
- Example:
01010101000001011011111100000001
- 32 bits divided into 4 Octets (Dotted Decimal Notation)
- Format:
01010101.00000101.10111111.00000001
- Structure: First Octet | Second Octet | Third Octet | Fourth Octet
Think of IPv4 like a postal address with 4 sections, where each section can range from 0 to 255
IPv6
- 128-bit address divided along 16-bit boundaries
- Each 16-bit block converted to 4-digit hexadecimal number
- Separated by colons (Colon-Hex Notation)
- Example:
FEDC:BA98:7654:3210:FEDC:BA98:7654:3210
Binary to Decimal Conversion
Example for First Octet:
- Total 8 bits with values 0's and 1's
- 28=256 combinations
| 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | Decimal |
|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 2 |
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 3 |
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 4 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 255 |
Total IP Address Range: 0.0.0.0 to 255.255.255.255 | | | | | | | | |
IP Address Classes
The total IP addressing scheme is divided into 5 Classes:
- CLASS A – LAN & WAN
- CLASS B – LAN & WAN
- CLASS C – LAN & WAN
- CLASS D – Multicasting
- CLASS E – Research & Development
Priority Bit Concept
To identify the range of each class, a priority bit is used (leftmost bits in the first octet):
- CLASS A: Priority bit is
0
- CLASS B: Priority bit is
10
- CLASS C: Priority bit is
110
- CLASS D: Priority bit is
1110
- CLASS E: Priority bit is
1111
Priority bits are like area codes - they tell you which "region" (class) an IP address belongs to
แต่ละ Class ดูยังไง ก็จะมี Priority bit นั่นก็คือ Leftmost bit in the first octet
CLASS A Range
Format: 0xxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx
First bit of first octet reserved for priority bit:
| 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | Decimal |
|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 127 |
Class A Range: 0.0.0.0 to 127.255.255.255
CLASS B Range
Format: 10xxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx
First two bits of first octet reserved for priority bit:
| 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | Decimal |
|---|
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 128 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 129 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 191 |
Class B Range: 128.0.0.0 to 191.255.255.255
CLASS C Range
Format: 110xxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx
First three bits of first octet reserved for priority bit:
| 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | Decimal |
|---|
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 192 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 193 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 223 |
Class C Range: 192.0.0.0 to 223.255.255.255
จากที่เราคุ้นเคยกันเลยล่ะ 192.168.1.1
CLASS D Range
Format: 1110xxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx
First four bits of first octet reserved for priority bit:
| 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | Decimal |
|---|
| 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 224 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 225 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 239 |
Class D Range: 224.0.0.0 to 239.255.255.255
CLASS E Range
Format: 1111xxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx
First four bits of first octet reserved for priority bit:
| 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | Decimal |
|---|
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 240 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 241 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 255 |
Class E Range: 240.0.0.0 to 255.255.255.255
IP address is divided into Network & Host Portion:
- CLASS A: N.H.H.H (Network.Host.Host.Host)
- CLASS B: N.N.H.H (Network.Network.Host.Host)
- CLASS C: N.N.N.H (Network.Network.Network.Host)
Think of N (Network) as the street name and H (Host) as the house number
CLASS A – Number of Networks & Hosts
Octet Format: N.H.H.H
- Network bits: 8
- Host bits: 24
Number of Networks:
Networks=28−1−2=27−2=128−2=126 Networks
- (-1 is for Priority Bit)
- (-2 is for network 0 and network 127) — เพราะว่ามัน Reserved!
Number of Hosts:
Hosts=224−2=16,777,216−2=16,777,214 Hosts/Network
- (-2 is for Network ID & Broadcast ID)
เยอะมาก พวกนี้ก็เป็นของ Service Provider (ISP) ทั้งหลาย ไม่ใช่ชาวบ้านแบบเรา ๆ
CLASS B – Number of Networks & Hosts
Octet Format: N.N.H.H
- Network bits: 16
- Host bits: 16
Number of Networks:
Networks=216−2−2=214−2=16,384−2=16,382 Networks
- (-2 is for Priority Bits)
- (-2 is for reserved networks)
Number of Hosts:
Hosts=216−2=65,536−2=65,534 Hosts/Network
- (-2 is for Network ID & Broadcast ID)
Middle-size network
CLASS C – Number of Networks & Hosts
Octet Format: N.N.N.H
- Network bits: 24
- Host bits: 8
Number of Networks:
Networks=224−3−2=221−2=2,097,152−2=2,097,150 Networks
- (-3 is for Priority Bits)
- (-2 is for reserved networks)
Number of Hosts:
Hosts=28−2=256−2=254 Hosts/Network
- (-2 is for Network ID & Broadcast ID)
Network & Broadcast Address
Key Concepts:
มาละ ตรงที่บอกว่าถูก Reserved อะ มันคือตรงนี้นั่นเองงง
- Network Address: All bits are ZERO in the host portion
- Broadcast Address: All bits are ONES in the host portion
- Valid IP Addresses: Lie between Network Address and Broadcast Address
- Only Valid IP Addresses are assigned to hosts/clients
Network address = "start of the street", Broadcast address = "end of the street", Valid IPs = "houses on the street"
Class A Example: Network 10.0.0.0
Format: N.H.H.H
- Network Address:
0xxxxxxx.00000000.00000000.00000000
- Broadcast Address:
0xxxxxxx.11111111.11111111.11111111
Example:
- Network Address:
10.0.0.0
- Valid IP Addresses:
10.0.0.1 to 10.255.255.254
- Broadcast Address:
10.255.255.255
Class B Example: Network 172.16.0.0
Format: N.N.H.H
- Network Address:
10xxxxxx.xxxxxxxx.00000000.00000000
- Broadcast Address:
10xxxxxx.xxxxxxxx.11111111.11111111
Example:
- Network Address:
172.16.0.0
- Valid IP Addresses:
172.16.0.1 to 172.16.255.254
- Broadcast Address:
172.16.255.255
Class C Example: Network 192.168.1.0
Format: N.N.N.H
- Network Address:
110xxxxx.xxxxxxxx.xxxxxxxx.00000000
- Broadcast Address:
110xxxxx.xxxxxxxx.xxxxxxxx.11111111
Example:
- Network Address:
192.168.1.0
- Valid IP Addresses:
192.168.1.1 to 192.168.1.254
- Broadcast Address:
192.168.1.255
Private IP Addresses
Certain addresses in each class are reserved for LAN (Local Area Network):
- Used for home & office networks
- Networks not connected to Internet
\begin{align}
\text{Class A: } &10.0.0.0 \text{ to } 10.255.255.255 \\
\text{Class B: } &172.16.0.0 \text{ to } 172.31.255.255 \\
\text{Class C: } &192.168.0.0 \text{ to } 192.168.255.255
\end{align}
}$$
> Private IPs are like internal phone extensions - they work within your building but can't be dialed from outside
>คือ Address พวกนี้มันจะไม่สามารถต่อตรงกับ Internet ได้นะ ถึงว่าวงในบ้านส่วนใหญ่มันเริ่มต้นด้วย 192.168.x.x ใช่มะ → แล้วจะต่อกับ Internet ยังไง? → ต้องทำบน Router NAT คอยแปลง Private IP เป็น Public IP ที่ ISP ให้มาชั่วคราว นี่เป็นการยืด IPv4 ให้ยังใช้ได้ถึงทุกวันนี้แบบไม่ซ้ำ
___
## Subnet Mask
>แล้ว Computer รู้ได้ไงว่า อย่าง IP ที่มันได้มาเช่น 192.168.1.100 ส่วนไหนคือ Network ส่วนไหนคือ Host?
>ก็ต้องมีตัวช่วยก็คือ **Subnet Mask**
**Purpose:**
- Differentiates Network portion and Host Portion
- Presented as all 1's in network portion and all 0's in host portion
>แต่เครื่องคอมพิวเตอร์ไม่รู้หรอกว่าจะแยกตรงไหน ถ้าไม่มี “หน้ากาก” เลยต้องมี **Subnet Mask** เพื่อ “บอกขอบเขต” ว่าส่วนไหนคือ Network และส่วนไหนคือ Host
### Default Subnet Masks
**Class A:** N.H.H.H
```
11111111.00000000.00000000.00000000
```
$$\boxed{\text{Default Subnet Mask: } 255.0.0.0}$$
**Class B:** N.N.H.H
```
11111111.11111111.00000000.00000000
```
$$\boxed{\text{Default Subnet Mask: } 255.255.0.0}$$
**Class C:** N.N.N.H
```
11111111.11111111.11111111.00000000
```
$$\boxed{\text{Default Subnet Mask: } 255.255.255.0}$$
## How Subnet Mask Works (AND Operation)
**Example:**
- IP Address: `192.168.1.1`
- Subnet Mask: `255.255.255.0`
**ANDING PROCESS:**
```
192.168.1.1 = 11000000.10101000.00000001.00000001
255.255.255.0 = 11111111.11111111.11111111.00000000
=========================================
192.168.1.0 = 11000000.10101000.00000001.00000000
```
>Network address (`192.168.1.0`) คือ “ชื่อเครือข่าย” ที่เครื่องนี้อยู่ในนั้น
**AND Truth Table:**
| A | B | C |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
> The output is 1 only if both inputs are 1, otherwise it's 0
## Subnetting
>แก้ปัญหาความไม่ยืดหยุ่นของ Class → กระบวนการที่แบ่งเครือข่ายใหญ่ ๆ ที่ได้มาตาม Class เอามาแบ่งเป็นเครือข่ายย่อย ๆ ตามที่ต้องการ **หลักการหลัก ๆ ก็คือการยืม Bit จากส่วนที่เคยเป็น Host มาเป็นส่วนของ Subnet แทน**
**Definition:**
- Process of ==breaking large network into small networks (subnets)==
- Extends default boundary of subnet mask
- Borrows host bits to create networks (dividing a single network into multiple networks)
- Converting host bits to network bits (changing 0's to 1's)
- Also called **FLSM (Fixed Length Subnet Mask)**
**Three Ways to Subnet:**
1. Requirement of Networks
2. Requirement of Hosts
3. Cisco / Notation
> Subnetting is like dividing a large apartment building into separate floors, each with its own address range
### Subnetting Scenario Example
**Given:** 100 PCs in 5 departments
**Which Class?** Class C (sufficient for 254 hosts)
#### Solution 1 (Poor):
```
- Sales: 192.168.1.1 to 192.168.1.20
- Accounting: 192.168.1.21 to 192.168.1.40
- Engineering: 192.168.1.41 to 192.168.1.60
- Management: 192.168.1.61 to 192.168.1.80
- Training: 192.168.1.81 to 192.168.1.100
```
**Problems:**
- Difficult to distinguish IP addresses for each department
- All use same network mask (255.255.255.0)
#### Solution 2 (Poor):
```
- Sales: 192.168.1.1 to 192.168.1.20
- Accounting: 192.168.2.1 to 192.168.2.20
- Engineering: 192.168.3.1 to 192.168.3.20
- Management: 192.168.4.1 to 192.168.4.20
- Training: 192.168.5.1 to 192.168.5.20
```
**Problems:**
- Loss of bandwidth (broadcasting for 254 machines instead of 20)
- Wastage of IP addresses (~1000 wasted รวมทั้ง 5 domain ละ)
- No security separation
**Best Solution:** Use Subnetting! ✓
### Subnetting Example 1
- **Requirement:** 5 Networks needed
- **Given:** Class C: `192.168.1.0`
- **Format:** `110xxxxx.xxxxxxxx.xxxxxxxx.xxx|xxxxx`
>Borrow from the host part สมมติขอมา 3 bits
#### Calculations:
**Number of Subnets:**
$$\text{Subnets} = 2^n - 2 \geq 5$$
$$2^3 - 2 = 8 - 2 = \boxed{6 \text{ Subnets}}$$
- We borrow 3 bits for subnetting
- (-2 is for First & Last Subnet Range)
**Number of Hosts:**
$$\text{Hosts} = 2^h - 2$$
$$\text{where } h = 8 - 3 = 5 \text{ bits remaining}$$
$$2^5 - 2 = 32 - 2 = \boxed{30 \text{ Hosts/Subnet}}$$
- (-2 is for Network ID & Broadcast ID)
>ก็คือเราสามารถ Support ได้ 30 PCs/Department อะไรทำนองนั้น
#### Custom Subnet Mask:
```
255.255.255.11100000
```
$$\boxed{\text{Custom Subnet Mask: } 255.255.255.224}$$
#### Subnet Ranges:
| Network ID | Valid Host Range | Broadcast ID | Status |
| ------------- | ---------------- | ------------- | --------- |
| 192.168.1.0 | — | 192.168.1.31 | Reserved |
| 192.168.1.32 | .33 to .62 | 192.168.1.63 | **Valid** |
| 192.168.1.64 | .65 to .94 | 192.168.1.95 | **Valid** |
| 192.168.1.96 | .97 to .126 | 192.168.1.127 | **Valid** |
| 192.168.1.128 | .129 to .158 | 192.168.1.159 | **Valid** |
| 192.168.1.160 | .161 to .190 | 192.168.1.191 | **Valid** |
| 192.168.1.192 | .193 to .222 | 192.168.1.223 | **Valid** |
| 192.168.1.224 | — | 192.168.1.255 | Reserved |
#### Department Allocation:
```
- Sales: 192.168.1.32 to 192.168.1.63 (30 hosts)
- Accounting: 192.168.1.64 to 192.168.1.95 (30 hosts)
- Engineering: 192.168.1.96 to 192.168.1.127 (30 hosts)
- Management: 192.168.1.128 to 192.168.1.159 (30 hosts)
- Training: 192.168.1.160 to 192.168.1.191 (30 hosts)
- Future Use: 192.168.1.192 to 192.168.1.223 (30 hosts)
```
### Subnetting Example 2
- **Requirement:** 14 Networks needed
- **Given:** Class C: `192.168.1.0`
- **Format:** `110xxxxx.xxxxxxxx.xxxxxxxx.xxxx|xxxx`
#### Calculations:
**Number of Subnets:**
$$\text{Subnets} = 2^n - 2 \geq 14$$
$$2^4 - 2 = 16 - 2 = \boxed{14 \text{ Subnets}}$$
- We borrow 4 bits for subnetting
- (-2 is for First & Last Subnet Range)
**Number of Hosts:**
$$\text{Hosts} = 2^h - 2$$
$$\text{where } h = 8 - 4 = 4 \text{ bits remaining}$$
$$2^4 - 2 = 16 - 2 = \boxed{14 \text{ Hosts/Subnet}}$$
#### Custom Subnet Mask:
```
255.255.255.11110000
```
$$\boxed{\text{Custom Subnet Mask: } 255.255.255.240}$$
#### Sample Subnet Ranges:
| Network ID | Valid Host Range | Broadcast ID | Status |
|-----------------|---------------------|-----------------|-------------|
| 192.168.1.0 | — | 192.168.1.15 | Reserved |
| 192.168.1.16 | .17 to .30 | 192.168.1.31 | **Valid** |
| 192.168.1.32 | .33 to .46 | 192.168.1.47 | **Valid** |
| 192.168.1.48 | .49 to .62 | 192.168.1.63 | **Valid** |
| 192.168.1.64 | .65 to .79 | 192.168.1.80 | **Valid** |
| ... | ... | ... | ... |
| 192.168.1.224 | .225 to .238 | 192.168.1.239 | **Valid** |
| 192.168.1.240 | — | 192.168.1.255 | Reserved |
### Important Note on Subnetting
> [!important]
>**The number of subnets must be a power of 2**
**Valid subnet counts:** 2, 4, 8, 16, 32, 64, 128, 256...
> IP addresses are designed with **two levels of hierarchy**:
> 1. Network portion
> 2. Host portion
> With subnetting, we create a **three-level hierarchy**:
> 1. Network prefix
> 2. Subnet number
> 3. Host number
## Basic Idea of Subnetting
**Process:**
- Split the host number portion of an IP address into:
- Subnet number
- Smaller host number
**Result:** 3-layer hierarchy
![[Pasted image 20251016094703.png|center|500]]
**Benefits:**
- Subnets can be freely assigned within the organization
- Internally, subnets are treated as separate networks
- Subnet structure is **not visible outside** the organization
## Subnet Example (Class B)
**Network Address:** `172.16.0.0` with `/16` network mask
### Without Subnetting:
```
172.16.0.Host (Network | Network | Host)
172.16.1.Host
172.16.2.Host
...
172.16.255.Host
```
### Using Subnets: `/24` or `255.255.255.0`
>**คือเขียนแบบนี้ก็ได้ /24 (คือจำนวน Bit ของ Network + รวมกับที่ยืมมาด้วย**)
**Structure:** Network | Network | Subnet | Host
![[Pasted image 20251016095035.png|center|500]]
**Calculations:**
- **Number of subnets:** $2^8 - 2 = 254$ valid subnets
- First subnet usually reserved
- Last subnet reserved for broadcast
- **Hosts per subnet:** $2^8 - 2 = 254$ hosts
- Each subnet has 254 usable host addresses
![[Pasted image 20251016095118.png|center|500]]
**Broadcast Addresses:**
![[Pasted image 20251016095100.png|center|500]]
---
## Advantages of Subnetting
1. **3-Layer Hierarchy:**
- Network
- Subnet
- Host
2. **Reduces Router Complexity:**
- External routers don't know about subnetting
- Complexity of routing tables at external routers is reduced
- Simplifies network management
3. **Better Organization:**
- Logical separation of departments/functions
- Improved security
- Efficient use of IP address space
---
## Default Mask vs Subnet Mask
![[Pasted image 20251016095230.png|center|400]]
### Without Subnetting (Default Mask)
**Example:** IP `141.14.72.24` with default mask `255.255.0.0`
```
141.14.72.24 = 11000000 00101101 01001000 00011000
255.255.0.0 = 11111111 11111111 00000000 00000000
=========================================
141.14.0.0 = 11000000 00101101 00000000 00000000
```
**Result:** Network Address = `141.14.0.0`
### With Subnetting (Subnet Mask)
**Example:** IP `141.14.72.24` with subnet mask `255.255.192.0`
```
141.14.72.24 = 11000000 00101101 01001000 00011000
255.255.192.0 = 11111111 11111111 11000000 00000000
=========================================
141.14.64.0 = 11000000 00101101 01000000 00000000
```
**Result:** Subnet Address = `141.14.64.0`
> The subnet mask creates a more specific network address by using additional bits
---
## Finding the Subnet Address
- Two methods to find subnet address:
1. **Straight Method:** Binary AND operation
2. **Short-Cut Method:** Selective copying
### Straight Method
Use binary notation for both address and mask, then apply AND operation.
**Example:** Find subnet address for `200.45.34.56` with mask `255.255.240.0` (/20)
```
200.45.34.56 = 11001000 00101101 00100010 00111000
255.255.240.0 = 11111111 11111111 11110000 00000000
=========================================
200.45.32.0 = 11001000 00101101 00100000 00000000
```
$$\boxed{\text{Subnet Address: } 200.45.32.0}$$
### Short-Cut Method
**Rules:**
1. If byte in mask is **255** → Copy the byte in the address
2. If byte in mask is **0** → Replace the byte in address with 0
3. If byte in mask is **neither 255 nor 0** → Use binary AND for that byte only
**Example:** Find subnet for `19.30.84.5` with mask `255.255.192.0` (/24)
```
IP: 19 . 30 . 84 . 5
Mask: 255 . 255 . 192 . 0
↓ ↓ ↓ ↓
19 . 30 . ? . 0
```
![[Pasted image 20251016095422.png|center|500]]
For the third byte (84 AND 192):
```
84 = 01010100
192 = 11000000
--------
64 = 01000000
```
$$\boxed{\text{Subnet Address: } 19.30.64.0}$$
## Comparison: Default Mask vs Subnet Mask
### Class B Example
**Default Mask:** `255.255.0.0`
```
11111111 11111111 | 00000000 00000000
←------ 16 -------→
Network bits
```
**Subnet Mask:** `255.255.224.0`
```
11111111 11111111 111 | 00000 00000000
←-------- 19 --------→ ←---- 13 ---→
Extended Network bits Host bits
↑___↑
3 subnet bits
```
> By borrowing 3 bits from the host portion, we can create $2^3 = 8$ subnets
---
## Subnetting Practice Example
>ค่อยแก้นะ
**Given:**
- **Host IP Address:** `172.16.18.33`
- **Network Mask:** `255.255.0.0`
- **Subnet Mask:** `255.255.255.0`
### Find:
#### Major Network Information:
- **Major Network Address:** `172.16.0.0`
- **Major Network Broadcast:** `172.16.255.255`
- **Range if not subnetted:** `172.16.0.1` to `172.16.255.254`
#### Subnet Information:
- **Subnet Address:** `172.16.18.0`
- **First Host:** `172.16.18.1`
- **Last Host:** `172.16.18.254`
- **Broadcast Address:** `172.16.18.255`
#### Other Subnet Information:
- **Total subnets:** $2^8 - 2 = 254$ subnets
- **Hosts per subnet:** $2^8 - 2 = 254$ hosts
---
## In-class Exercise 1: Class B Subnetting
**Given:**
- Site address: `181.56.0.0` (Class B)
- Requirement: 1000 subnets
### Solution:
**Step 1:** Determine bits needed for subnets
- Default mask has **16 ones** (Class B)
- Need 1000 subnets
- 1000 is not a power of 2
- Next power of 2: $2^{10} = 1024$ ≥ 1000
- Need to borrow **10 bits** from host portion
**Step 2:** Calculate subnet mask
- Total 1s in subnet mask: $16 + 10 = 26$
- Total 0s: $32 - 26 = 6$
**Subnet Mask:**
```
11111111.11111111.11111111.11000000
```
$\boxed{\text{Subnet Mask: } 255.255.255.192 \text{ or } /26}$
**Step 3:** Calculate results
- **Number of subnets:** $2^{10} = 1024$ subnets
- **Hosts per subnet:** $2^6 - 2 = 64 - 2 = 62$ hosts
---
## In-class Exercise 2: Finding Subnet Information
**Given:**
- **Host IP Address:** `138.101.114.250`
- **Network Mask:** `255.255.0.0`
- **Subnet Mask:** `255.255.255.192`
### Major Network Information:
- **Major Network Address:** `138.101.0.0`
- **Major Network Broadcast:** `138.101.255.255` (Last address)
- **Range if not subnetted:** `138.101.0.1` to `138.101.255.254`
### Finding Subnet Address:
Using the short-cut method:
```
IP: 138 . 101 . 114 . 250
Mask: 255 . 255 . 255 . 192
↓ ↓ ↓ ↓
138 . 101 . 114 . ?
```
For the fourth byte (250 AND 192):
```
250 = 11111010
192 = 11000000
--------
192 = 11000000
```
**Subnet Address:** `138.101.114.192`
### Subnet Information:
- **Subnet Address:** `138.101.114.192`
- **First Host:** `138.101.114.193`
- **Last Host:** `138.101.114.254`
- **Broadcast Address:** `138.101.114.255`
### Other Subnet Information:
**Bits borrowed:** 10 bits (subnet mask has 26 ones, default has 16)
- **Total subnets:** $2^{10} = 1024$ subnets
- **Hosts per subnet:** $2^6 - 2 = 62$ hosts
---
## Variable-Length Subnetting (VLSM)
>อนุญาตให้เราใช้ Subnet Mask ที่มันขนาดแตกต่างกันได้ ภายในเครือข่ายหลักเดียวกัน
VLSM allows different subnet masks within the same network to optimize IP address usage.
![[Pasted image 20251016095715.png|center|500]]
### Example Scenario:
**Site:** `X.Y.Z.0`
**Requirements:**
- 3 subnets with 62 hosts each
- 2 subnets with 30 hosts each
### Solution:
**First Level Subnetting:**
- **First Mask:** `255.255.255.192` (/26)
- Creates subnets with 62 usable hosts
- For the three 62-host networks
**Second Level Subnetting:**
- **Second Mask:** `255.255.255.224` (/27)
- Creates subnets with 30 usable hosts
- Further subdivide one /26 subnet into two /27 subnets
> VLSM is like having different-sized rooms in a building - you use the space more efficiently by matching room size to actual needs
### Benefits:
- Efficient IP address utilization
- Flexibility in network design
- Reduced IP address wastage
- Better scalability
---
## Appendix: Reference Tables
### Power Table
| Power | Value | Power | Value |
|-------|--------------|-------|--------------|
| $2^1$ | 2 | $2^{17}$ | 131,072 |
| $2^2$ | 4 | $2^{18}$ | 262,144 |
| $2^3$ | 8 | $2^{19}$ | 524,288 |
| $2^4$ | 16 | $2^{20}$ | 1,048,576 |
| $2^5$ | 32 | $2^{21}$ | 2,097,152 |
| $2^6$ | 64 | $2^{22}$ | 4,194,304 |
| $2^7$ | 128 | $2^{23}$ | 8,388,608 |
| $2^8$ | 256 | $2^{24}$ | 16,777,216 |
| $2^9$ | 512 | $2^{25}$ | 33,554,432 |
| $2^{10}$ | 1,024 | $2^{26}$ | 67,108,864 |
| $2^{11}$ | 2,048 | $2^{27}$ | 134,217,728 |
| $2^{12}$ | 4,096 | $2^{28}$ | 268,435,456 |
| $2^{13}$ | 8,192 | $2^{29}$ | 536,870,912 |
| $2^{14}$ | 16,384 | $2^{30}$ | 1,073,741,824 |
| $2^{15}$ | 32,768 | $2^{31}$ | 2,147,483,648 |
| $2^{16}$ | 65,536 | $2^{32}$ | 4,294,967,296 |
---
### Important Subnet Mask Values
| Bits | Binary | Decimal | CIDR |
|------|-----------|---------|------|
| 1 | 10000000 | 128 | /25 |
| 2 | 11000000 | 192 | /26 |
| 3 | 11100000 | 224 | /27 |
| 4 | 11110000 | 240 | /28 |
| 5 | 11111000 | 248 | /29 |
| 6 | 11111100 | 252 | /30 |
| 7 | 11111110 | 254 | /31 |
| 8 | 11111111 | 255 | /32 |
> Memorize these values! They're essential for quick subnet calculations
---
## Quick Reference: Subnetting Formulas
### Number of Subnets
$\boxed{\text{Subnets} = 2^n - 2}$
where $n$ = number of borrowed bits
> Some modern networks don't subtract 2, using all subnets including first and last
### Number of Hosts per Subnet
$\boxed{\text{Hosts} = 2^h - 2}$
where $h$ = number of remaining host bits
- Subtract 2 for Network ID and Broadcast ID
### Total Bits in Subnet Mask
$\boxed{\text{Total 1s} = \text{Default mask bits} + \text{Borrowed bits}}$
### Finding Network Increment
$\boxed{\text{Increment} = 256 - \text{Subnet octet value}}$
**Example:** For mask `255.255.255.224`
- Increment = $256 - 224 = 32$
- Subnets: 0, 32, 64, 96, 128, 160, 192, 224
---
## Subnetting Strategy Guide
### Step-by-Step Process:
1. **Identify the class** (A, B, or C) from the IP address
2. **Determine requirements:**
- How many subnets needed?
- How many hosts per subnet?
3. **Calculate bits to borrow:**
- For subnets: Find smallest $n$ where $2^n \geq$ required subnets
- For hosts: Find smallest $h$ where $2^h - 2 \geq$ required hosts
4. **Create custom subnet mask:**
- Add borrowed bits to default mask
5. **Calculate subnet ranges:**
- Find increment value
- List all subnet boundaries
6. **Assign subnets** to network segments
### Common Subnet Mask Quick Reference:
| CIDR | Subnet Mask | # Hosts | Class C Subnets |
|------|-------------------|---------|-----------------|
| /24 | 255.255.255.0 | 254 | 1 |
| /25 | 255.255.255.128 | 126 | 2 |
| /26 | 255.255.255.192 | 62 | 4 |
| /27 | 255.255.255.224 | 30 | 8 |
| /28 | 255.255.255.240 | 14 | 16 |
| /29 | 255.255.255.248 | 6 | 32 |
| /30 | 255.255.255.252 | 2 | 64 |
---
## Tips and Tricks
### Quick IP Class Identification:
- **Class A:** First octet 1-126 (starts with 0)
- **Class B:** First octet 128-191 (starts with 10)
- **Class C:** First octet 192-223 (starts with 110)
- **Class D:** First octet 224-239 (starts with 1110) - Multicast
- **Class E:** First octet 240-255 (starts with 1111) - Reserved
### Special Addresses to Remember:
- `127.x.x.x` - Loopback (localhost)
- `0.0.0.0` - Default route
- `255.255.255.255` - Broadcast to all
### Binary Conversion Shortcuts:
- **128** = 10000000
- **192** = 11000000
- **224** = 11100000
- **240** = 11110000
- **248** = 11111000
- **252** = 11111100
- **254** = 11111110
- **255** = 11111111
### Common Pitfalls to Avoid:
1. ❌ Forgetting to subtract 2 for network and broadcast addresses
2. ❌ Not using power of 2 for subnet count
3. ❌ Mixing up host bits and network bits
4. ❌ Using first or last subnet (in older routing protocols)
5. ❌ Forgetting that /24, /16, /8 are the default masks
---
## Practice Problems Summary
### Problem Type 1: Given Subnet Requirements
**Find:** Custom subnet mask, number of hosts
**Example:** Need 6 subnets in Class C
- Use 3 bits ($2^3 = 8 \geq 6$)
- Mask: 255.255.255.224
- Hosts per subnet: $2^5 - 2 = 30$
### Problem Type 2: Given IP and Masks
**Find:** Network address, subnet address, broadcast address, host range
**Example:** IP `172.16.18.33` with mask `255.255.255.0`
- Network: 172.16.0.0
- Subnet: 172.16.18.0
- Broadcast: 172.16.18.255
- Host range: 172.16.18.1 - 172.16.18.254
### Problem Type 3: VLSM Design
**Find:** Optimal subnet allocation for varying host requirements
**Strategy:**
- Start with largest subnet requirement
- Allocate from beginning of address space
- Subdivide remaining space for smaller subnets
---
## Final Notes
### Key Takeaways:
1. ✅ Subnetting creates logical network divisions
2. ✅ Always use powers of 2 for subnet calculations
3. ✅ Remember to subtract 2 (network ID and broadcast)
4. ✅ External routers don't see internal subnetting
5. ✅ VLSM allows different mask lengths for efficiency
### When to Use Each Class:
- **Class A:** Very large organizations (millions of hosts)
- **Class B:** Medium to large organizations (thousands of hosts)
- **Class C:** Small organizations (up to 254 hosts)
### Modern Considerations:
- **CIDR** (Classless Inter-Domain Routing) is now more common than classful addressing
- **IPv6** is gradually replacing IPv4 due to address exhaustion
- **Private IP ranges** are essential for NAT (Network Address Translation)