> For the complete documentation index, see [llms.txt](https://netsec.nerd-cafe.ir/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://netsec.nerd-cafe.ir/network-engineering/comptia-network+/n10-007/ipv4-addressing-and-classes.md).

# IPv4 Addressing & Classes

Nerd Cafe

### 16,384 (2¹⁴)<mark style="color:blue;">**1. Introduction to IPv4**</mark>

IPv4 (Internet Protocol version 4) is the fourth version of the Internet Protocol, and it is the most widely used protocol for identifying devices on a network. IPv4 uses a <mark style="color:red;">**32-bit address**</mark>, which is expressed as <mark style="color:red;">**four octets (8-bit values)**</mark> separated by <mark style="color:red;">**dots (.)**</mark>.

#### **Example of an IPv4 Address:**

```ini
192.168.1.1
```

Each octet is represented in <mark style="color:red;">**decimal form**</mark> and ranges from <mark style="color:red;">**0 to 255**</mark> (since 8-bit binary numbers range from `00000000` to `11111111` in binary, which equals `0 to 255` in decimal).

### <mark style="color:blue;">**2. IPv4 Addressing Format**</mark>

An IPv4 address consists of two parts:

1. <mark style="color:red;">**Network Portion**</mark> – Identifies the network to which the device belongs.
2. <mark style="color:red;">**Host Portion**</mark> – Identifies a specific device (host) within the network.

The separation between the <mark style="color:red;">**network**</mark> and <mark style="color:red;">**host**</mark> portions depends on the <mark style="color:red;">**subnet mask**</mark>.

### <mark style="color:blue;">**3. IPv4 Address Classes**</mark>

IPv4 addresses are divided into <mark style="color:red;">**five classes (A, B, C, D, E)**</mark> based on their <mark style="color:red;">**first octet**</mark>. Each class has different network and host allocations.

<table><thead><tr><th width="75">Class</th><th width="132">First Octet Range</th><th>Default Subnet Mask</th><th>Networks Available</th><th>Hosts per Network</th><th>Purpose</th></tr></thead><tbody><tr><td>A</td><td>1 - 126</td><td>255.0.0.0</td><td>128 (2⁷ - 2)</td><td>16,777,214 (2²⁴ - 2)</td><td>Large networks (e.g., ISPs, big enterprises)</td></tr><tr><td>B</td><td>128 - 191</td><td>255.255.0.0</td><td>16,384 (2¹⁴)</td><td>65,534 (2¹⁶ - 2)</td><td>Medium-sized businesses and organizations</td></tr><tr><td>C</td><td>192 - 223</td><td>255.255.255.0</td><td>2,097,152 (2²¹)</td><td>254 (2⁸ - 2)</td><td>Small businesses and local networks</td></tr><tr><td>D</td><td>224 - 239</td><td>N/A</td><td>N/A</td><td>N/A</td><td>Multicast groups (not used for host addressing)</td></tr><tr><td>E</td><td>240 - 255</td><td>N/A</td><td>N/A</td><td>N/A</td><td>Experimental use (Reserved by IETF)</td></tr></tbody></table>

**Note:**

* The first octet range <mark style="color:red;">**127**</mark> is reserved for <mark style="color:red;">**loopback addresses**</mark> (e.g., `127.0.0.1` is used for local testing).
* The <mark style="color:red;">**subnet mask**</mark> helps define the boundary between the <mark style="color:red;">**network**</mark> and <mark style="color:red;">**host**</mark> portions.

### <mark style="color:blue;">**4. Binary Representation of IPv4 Addresses**</mark>

Each octet in an IPv4 address is an <mark style="color:red;">**8-bit binary number**</mark>.

#### **Example:** Convert `192.168.1.1` into Binary:

1. Convert each octet into an 8-bit binary format:
   * `192` → `11000000`
   * `168` → `10101000`
   * `1` → `00000001`
   * `1` → `00000001`

Thus,

```ini
192.168.1.1  =  11000000.10101000.00000001.00000001 (Binary)
```

This binary format is useful for subnetting, CIDR notation, and routing decisions.

### <mark style="color:blue;">**5. Private vs Public IPv4 Addresses**</mark>

IPv4 addresses are categorized into <mark style="color:red;">**public**</mark> and <mark style="color:red;">**private**</mark> ranges.

#### **Private IPv4 Address Ranges (RFC 1918)**

<table><thead><tr><th width="79">Class</th><th width="276">Private IP Range</th><th>CIDR Notation</th><th>Total IPs</th></tr></thead><tbody><tr><td>A</td><td>10.0.0.0 – 10.255.255.255</td><td>10.0.0.0/8</td><td>16,777,216</td></tr><tr><td>B</td><td>172.16.0.0 – 172.31.255.255</td><td>172.16.0.0/12</td><td>1,048,576</td></tr><tr><td>C</td><td>192.168.0.0 – 192.168.255.255</td><td>192.168.0.0/16</td><td>65,536</td></tr></tbody></table>

* <mark style="color:red;">**Private IPs**</mark> are used inside organizations and home networks and are not routable on the public internet.
* <mark style="color:red;">**Public IPs**</mark> are assigned by ISPs and used to connect to the internet.

### <mark style="color:blue;">**6. IPv4 Addressing Practical Lab**</mark>

Let’s perform a practical IPv4 addressing scenario.

#### **Scenario:**

You are given the network `192.168.10.0/24`. You need to assign IPv4 addresses to 5 devices.

<figure><img src="https://2804731566-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLOszSitBb46QATDLUtW4%2Fuploads%2F9ceqTfiQ7Wya1QWrwcCM%2F0495-topology.png?alt=media&amp;token=7a57e32b-ec30-44ed-9436-05b18cc97e23" alt=""><figcaption><p>Topology</p></figcaption></figure>

#### **Steps:**

1. **Identify Network Address:** `192.168.10.0`
2. **Identify Subnet Mask:** `255.255.255.0`
3. **Find Usable Host IP Range:** `192.168.10.1 – 192.168.10.254`
4. **Assign IPs to Devices:**
   * Router: `192.168.10.1`
   * PC1: `192.168.10.10`
   * PC2: `192.168.10.20`
   * Server: `192.168.10.30`
   * Printer: `192.168.10.40`
5. **Broadcast Address:** `192.168.10.255`
6. **Validation:** Use the **ping** command to test connectivity.

#### R1 Configuration

```
Router#configure terminal
Router(config)#interface fastEthernet 0/0
Router(config-if)#ip address 192.168.10.1 255.255.255.0
Router(config-if)#no shut
```

#### PC1 Configuration

```
PC1> ip 192.168.10.10/24 192.168.10.1
Checking for duplicate address...
PC1 : 192.168.10.10 255.255.255.0 gateway 192.168.10.1

PC1> show ip

NAME        : PC1[1]
IP/MASK     : 192.168.10.10/24
GATEWAY     : 192.168.10.1
DNS         :
MAC         : 00:50:79:66:68:00
LPORT       : 20012
RHOST:PORT  : 127.0.0.1:20013
MTU         : 1500

PC1> save
Saving startup configuration to startup.vpc
.  done

PC1>
```

#### PC2 Configuration

```
PC2> ip 192.168.10.20/24 192.168.10.1
Checking for duplicate address...
PC2 : 192.168.10.20 255.255.255.0 gateway 192.168.10.1

PC2> show ip

NAME        : PC2[1]
IP/MASK     : 192.168.10.20/24
GATEWAY     : 192.168.10.1
DNS         :
MAC         : 00:50:79:66:68:01
LPORT       : 20014
RHOST:PORT  : 127.0.0.1:20015
MTU         : 1500

PC2> save
Saving startup configuration to startup.vpc
.  done

PC2>
```

#### Server Configiration

```
Server> ip 192.168.10.30/24 192.168.10.1
Checking for duplicate address...
Server : 192.168.10.30 255.255.255.0 gateway 192.168.10.1

Server> show ip

NAME        : Server[1]
IP/MASK     : 192.168.10.30/24
GATEWAY     : 192.168.10.1
DNS         :
MAC         : 00:50:79:66:68:02
LPORT       : 20016
RHOST:PORT  : 127.0.0.1:20017
MTU         : 1500

Server> save
Saving startup configuration to startup.vpc
.  done

Server>
```

#### Printer Configuration

```
Printer> ip 192.168.10.40/24 192.168.10.1
Checking for duplicate address...
Printer : 192.168.10.40 255.255.255.0 gateway 192.168.10.1

Printer> show ip

NAME        : Printer[1]
IP/MASK     : 192.168.10.40/24
GATEWAY     : 192.168.10.1
DNS         :
MAC         : 00:50:79:66:68:03
LPORT       : 20018
RHOST:PORT  : 127.0.0.1:20019
MTU         : 1500

Printer> save
Saving startup configuration to startup.vpc
.  done

Printer>
```

#### Connectivity Tests

```
PC1> ping 192.168.10.1

84 bytes from 192.168.10.1 icmp_seq=1 ttl=255 time=50.985 ms
84 bytes from 192.168.10.1 icmp_seq=2 ttl=255 time=13.339 ms
^C
PC1> ping 192.168.10.20

84 bytes from 192.168.10.20 icmp_seq=1 ttl=64 time=0.599 ms
84 bytes from 192.168.10.20 icmp_seq=2 ttl=64 time=0.665 ms
^C
PC1> ping 192.168.10.30

84 bytes from 192.168.10.30 icmp_seq=1 ttl=64 time=0.521 ms
84 bytes from 192.168.10.30 icmp_seq=2 ttl=64 time=0.531 ms
^C
PC1> ping 192.168.10.40

84 bytes from 192.168.10.40 icmp_seq=1 ttl=64 time=0.668 ms
84 bytes from 192.168.10.40 icmp_seq=2 ttl=64 time=0.742 ms
^C
PC1>
```

### <mark style="color:blue;">**7. Configuring IPv4 Address in Windows/Linux**</mark>

#### **Windows:**

* Open **Command Prompt** (`cmd`).
* Type:

```
C:\Users\nerd-cafe>ipconfig

Windows IP Configuration

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::298e:fec6:a21f:8a40%38
   IPv4 Address. . . . . . . . . . . : 192.168.1.244
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

C:\Users\nerd-cafe>
```

This shows current IP settings.

* To set an IPv4 address manually:

```powershell
netsh interface ip set address "Ethernet" static 192.168.10.10 255.255.255.0 192.168.10.1
```

* `192.168.10.10` → IP Address
* `255.255.255.0` → Subnet Mask
* `192.168.10.1` → Default Gateway

#### **Linux:**

1. Open **Terminal**.
2. Check current IP:

```sh
ifconfig
```

or

```sh
ip addr show
```

* Assign an IPv4 address manually:

```sh
sudo ifconfig eth0 192.168.10.10 netmask 255.255.255.0
```

or

```sh
sudo ip addr add 192.168.10.10/24 dev eth0
```

### <mark style="color:blue;">**8. Summary**</mark>

* IPv4 uses a **32-bit** address and is represented in **decimal form**.
* It is divided into **five classes (A, B, C, D, E)**.
* **Private IPv4 addresses** are used for internal networks.
* **Subnet masks** determine the **network/host boundary**.
* IPv4 can be configured using **Windows (netsh) or Linux (ifconfig/ip)**.
* Practical IPv4 addressing is essential for **networking professionals**.

### <mark style="color:blue;">Keywords</mark>

`IPv4 addressing`, `IP classes`, `subnet mask`, `network portion`, `host portion`, `Class A`, `Class B`, `Class C`, `Class D`, `Class E`, `private IP`, `public IP`, `CIDR notation`, `binary representation`, `loopback address`, `default gateway`, `IP configuration`, `DHCP`, `static IP`, `IP routing`, `نتورک پلاس`
