Subnetting is the practice of dividing an IP network into smaller network segments or subnets. This is typically done to manage and allocate IP addresses more efficiently within an organization and to improve network performance and security.

In IPv4, an IP address consists of 32 bits and is represented in a dotted-decimal format. For example: 192.168.1.1. Each segment in this format can range from 0 to 255, as it represents 8 bits (one octet).

**Prefix Notation**: Subnets are often represented using CIDR (Classless Inter-Domain Routing) notation. In CIDR, a prefix length is appended to an IP address to specify the number of bits set to '1' in the subnet mask. For example: 192.168.1.0/24 Here, the '/24' indicates that the first 24 bits are the network portion, and the remaining 8 bits (32-24) are available for host addresses within that subnet.

**Basic Subnetting**:

Determine how many subnets or hosts per subnet you need.

Convert those needs into binary to determine the number of bits required.

Adjust the subnet mask accordingly.

**Workshop Exercises and Solutions**:

**Exercise 1**: If you have the network 192.168.1.0/24 and need to divide it into 2 subnets, what will the new subnets and subnet masks be?

**Solution**: You need 2 subnets, which means you need at least 1 extra bit (because 2^1 = 2). This means the new subnet mask will be /25 (24 original + 1 extra bit). Subnets:

192.168.1.0/25 (hosts from 192.168.1.1 to 192.168.1.126 with 192.168.1.127 as broadcast)

192.168.1.128/25 (hosts from 192.168.1.129 to 192.168.1.254 with 192.168.1.255 as broadcast)

Subnetting, in essence, is the act of taking a larger network and breaking it down into smaller networks or subnets. To accomplish this, you need to "borrow" bits from the host portion of the address and use them for the network/subnet portion.

Let's use the 192.168.1.0/24 example:

Original:

- Network: 192.168.1.0/24 (Network portion is 24 bits, Host portion is 8 bits)

If you were asked to split this into 2 separate subnets, you have to determine how many additional bits you'd need to achieve this. In this case, the "extra bit" you're borrowing from the host portion is to differentiate between the two subnets.

Let's visualize with binary for the host portion:

Original (8 host bits): 00000000

With 1 extra bit borrowed for subnetting:

Subnet 1: 0xxxxxxx

Subnet 2: 1xxxxxxx

By "borrowing" just one bit, you can create two distinct subnets. The "x" represents the remaining bits for hosts.

If you borrowed two bits, you could represent 4 distinct subnets:

00xxxxxx

01xxxxxx

10xxxxxx

11xxxxxx

This is the logic behind "needing one extra bit". For every bit you borrow from the host portion, you double the number of subnets you can create.

1 bit = 2 subnets

2 bits = 4 subnets

3 bits = 8 subnets ...and so on.

However, every bit you borrow for subnets reduces the number of available host addresses in each subnet.

**Exercise 2**: If you have the network 10.0.0.0/8 and need to create subnets each containing 1000 hosts, what will the subnet mask be?

**Solution**: For 1000 hosts, you need at least 10 bits (since 2^10 = 1024. Deduct 2 for network and broadcast addresses, leaving 1022 usable hosts). 32 (total bits) - 10 (host bits) = 22 bits for the network. The subnet mask will be /22.

Of course! Let's go through more subnetting exercises:

**Exercise 3:** You have a network 172.16.0.0/16, and you need to divide it into 8 equal subnets. What will be the subnet mask for each of these subnets?

**Solution for Exercise 3:** To create 8 subnets, you'd need 3 bits (2^3 = 8). This means borrowing 3 bits from the host portion. So, 16 original bits + 3 borrowed bits = 19 bits. Each of the 8 subnets will have a subnet mask of /19.

**Exercise 4:** You are given the network 10.10.0.0/16 and need to create subnets, each containing at least 500 hosts. What is the subnet mask you should use?

**Solution for Exercise 4:** For at least 500 hosts, you need 9 bits (since 2^9 = 512). However, 2 addresses are reserved for network and broadcast, leaving exactly 510 usable addresses. This means 32 - 9 = 23 bits for the network. So, the subnet mask will be /23.

**Exercise 5:** You have a network address of 192.168.5.0/24, and you're asked to create 4 equal subnets. List the range of IP addresses for each subnet and the broadcast address for each.

**Solution for Exercise 5:** Borrowing 2 bits (since 2^2 = 4), the subnet mask becomes /26. The subnets are:

192.168.5.0/26 (hosts: 192.168.5.1 to 192.168.5.62, broadcast: 192.168.5.63)

192.168.5.64/26 (hosts: 192.168.5.65 to 192.168.5.126, broadcast: 192.168.5.127)

192.168.5.128/26 (hosts: 192.168.5.129 to 192.168.5.190, broadcast: 192.168.5.191)

192.168.5.192/26 (hosts: 192.168.5.193 to 192.168.5.254, broadcast: 192.168.5.255)

Let's delve deeper into Exercise 5:

**Determining the Bits to Borrow:** 2^x = number of subnets required 2^x = 4 From this, we find that x = 2.

This means we need to borrow 2 bits to create 4 subnets.

Original subnet mask: /24 After borrowing 2 bits: /24 + 2 = /26

So, each of the new subnets will have a subnet mask of /26.

**Defining Subnets using the Borrowed Bits:**

**First Subnet:**Network Address: 192.168.5.0 (where the last 8 bits are 00000000 in binary) Last Address in this subnet: 192.168.5.63 (where the last 8 bits are 00111111 in binary)So, for the 192.168.5.0/26 subnet:

Network Address: 192.168.5.0

First Usable Address: 192.168.5.1

Last Usable Address: 192.168.5.62

Broadcast Address: 192.168.5.63

**Second Subnet:**Network Address: 192.168.5.64 (where the last 8 bits are 01000000 in binary) Last Address in this subnet: 192.168.5.127 (where the last 8 bits are 01111111 in binary)So, for the 192.168.5.64/26 subnet:

Network Address: 192.168.5.64

First Usable Address: 192.168.5.65

Last Usable Address: 192.168.5.126

Broadcast Address: 192.168.5.127

**Third Subnet:**Network Address: 192.168.5.128 (where the last 8 bits are 10000000 in binary) Last Address in this subnet: 192.168.5.191 (where the last 8 bits are 10111111 in binary)So, for the 192.168.5.128/26 subnet:

Network Address: 192.168.5.128

First Usable Address: 192.168.5.129

Last Usable Address: 192.168.5.190

Broadcast Address: 192.168.5.191

**Fourth Subnet:**Network Address: 192.168.5.192 (where the last 8 bits are 11000000 in binary) Last Address in this subnet: 192.168.5.255 (where the last 8 bits are 11111111 in binary)So, for the 192.168.5.192/26 subnet:

Network Address: 192.168.5.192

First Usable Address: 192.168.5.193

Last Usable Address: 192.168.5.254

Broadcast Address: 192.168.5.255

In essence, each time you borrow a bit for subnetting, you're further dividing the address space. In this case, borrowing two bits divided our original /24 network into 4 equal /26 subnets. The IP range of each subnet is determined based on the binary representation of the borrowed bits.

**Exercise 6:** Given a network address of 10.0.0.0/8, if you're asked to subnet this into networks each having 4000 hosts, what would be the subnet mask for these subnets?

**Solution for Exercise 6:** For 4000 hosts, you need 12 bits (2^12 = 4096, leaving 4094 usable after deducting network and broadcast). This means 32 - 12 = 20 bits for the network. The subnet mask will be /20.

**Exercise 7:** You've been allocated an IP range of 203.0.113.0/27 and need to divide it into as many subnets as possible with each subnet having at least 16 hosts. How many subnets can you create and what is the subnet mask?

**Solution for Exercise 7:** For at least 16 hosts, you need 5 bits (since 2^5 = 32, but with 2 addresses reserved, you get 30 usable addresses which is enough for the requirement). The original subnet mask is /27. By borrowing 3 bits (since 2^3 = 8 and 5 bits remain for hosts), the new subnet mask becomes /30. Thus, you can create 8 subnets with the mask /30 from the original /27 network.