> For the complete documentation index, see [llms.txt](https://neerajcysec.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://neerajcysec.gitbook.io/notes/networking/ccna-notes/subnetting-2.md).

# Subnetting (2)

{% embed url="<https://youtu.be/IGhd-0di0Qo>" %}

## Review

* [Subnetting (1)](/notes/networking/ccna-notes/subnetting-1.md)

## Subnet exercises

### Number of subnets

* No. of subnets = 2^x, where x = no. of borrowed bits.
* If you want 5 subnets, you'll need to use /27 mask.
* /27 mask has 3 borrowed bits which gives 8 subnets (2^3).

### Identify each subnet

* Divide 192.168.255.0/24 into 5 subnets of equal size.
* Find the number of subnets from the previous step [#number-of-subnets](#number-of-subnets "mention")
* To find the subnets, consider the last octet.
* You have 3 borrowed bits and 5 host bits.
* The 3rd borrowed bit from the left corresponds to 32nd place in the octet.
* Now, add 32 to the first address (first subnet) to get the next subnet and so on.
* 192.168.255.0/27, ..255.32/27, ..255.64/27, ..255.96/27, ..255.128/27
* However there will be 3 other subnets as /27 prefix length allows upto 8 subnets.

### Identify the subnet

What subnet does host 192.168.5.57/27 belong to?

* Convert it into dotted decimal.
* Its last octet is 00111001.
* The first 3 are the borrowed bits since /27 mask.
* To find the network or the subnet the host is in, **change all the host bits to 0**.
* **Convert back to dotted decimal.** It leaves us with the last octet of 00100000 which equals 32.
* This means the host belongs to the subnet 192.168.5.32/27.
* Another example : 192.168.29.219/29 belongs to 192.168.29.216/29 subnet.

## Subnets of Class C

| Prefix | Subnets | Hosts |
| ------ | ------- | ----- |
| /25    | 2       | 126   |
| /26    | 4       | 62    |
| /27    | 8       | 30    |
| /28    | 16      | 14    |
| /29    | 32      | 6     |
| /30    | 64      | 2     |
| /31    | 128     | 0(2)  |
| /32    | 256     | 0(1)  |

* Each bit you borrow doubles the number of subnets.
* [Subnetting (1)#31 mask](/notes/networking/ccna-notes/subnetting-1.md#31-mask)
* [Subnetting (1)#32 mask](/notes/networking/ccna-notes/subnetting-1.md#32-mask)

## Subnetting Class B

* Class B has more host bits than Class C, which means many more possible subnets can be created with a Class B network compared to Class C.

> The process of subnetting Class A, B, C networks is EXACTLY the same.

### Number of subnets

**Example 1**

172.16.0.0/16 network. Create 80 subnets for your company's various LANs. What prefix length to use?

* Use 2^x formula.
* If you don't borrow any bit, you can't make a subnet. It's just one large /16 network.
* If you borrow 1 bit, you can make 2 subnets, with a prefix of /17 and a mask of 255.255.128.0
* Borrowing 7 bits gives us 128 subnets, with a mask of /23 and a mask of 255.255.254.0
* To find the subnets, add the value of the last borrowed bit, which is 2 (because the 7th bit is 2nd place).
* Some subnets are 192.168.0.0/23, 192.168.2.0/27, 192.168.4.0/27, 192.168.6.0/27 and so on.

**Example 2**

172.22.0.0/16 network. Divide the network into 500 subnets. Identify the prefix length to be used.

* 9 borrowed bits creates 512 subnets, so the prefix length would be /25, with a mask of 255.255.255.128
* Every possible subnet in the 3rd octet (256) has a combination on 0 and 1 from the 1st bit of 4th octet, which makes 512 subnets.

**Example 3**

172.18.0.0/16 network. Company requires 250 subnets with same number of hosts per subnet. Find the prefix length to be used.

* Borrowing 8 bits gives 256 subnets.
* This also gives 8 host bits, which equals 254 hosts per subnet.

### Identify the subnet

What subnet does host 172.25.217.192/21 belong to?

* Write the address in binary.
* Identify the borrowed bits.
* Change the hosts to 0.
* Convert back to dotted decimal.
* You get 172.25.216.0/21

<figure><img src="https://935233489-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGyWMBzIPoBvXNyR5UOW%2Fuploads%2FLu6iXLb5SAOF1u4Ilwaw%2FSubnet%20Class%20B.png?alt=media&amp;token=f51891f9-32ad-4593-9f9c-44b48a713200" alt=""><figcaption></figcaption></figure>

*number of hosts in /21 subnet is 2046 and not 2044*

Continued : [Subnetting (3)](/notes/networking/ccna-notes/subnetting-3.md)

## Quiz

1. 172.30.0.0/16 network. 100 subnets with atleast 500 hosts per subnet. Find the prefix length.
   * Borrowing 7 bits gives 128 subnets and leaves us with 512 hosts (9 bits, 510 usable addresses).
   * So /23 prefix is used which has a mask of 255.255.254.0
2. 172.21.111.201/20. Identify the subnet
   * Write in binary (last 2 octets : 01101111.11001001)
   * Change host bits to 0 (last 2 octets : **0110**0000.00000000)
   * Convert back to dotted decimal - 172.21.96.0/20
3. 192.168.91.78/26. Find the broadcast address of the network of the address
   * Same prev steps
   * Change all host bits to 1 instead.
   * 192.168.91.127
4. 172.16.0.0/16 network. Divide into 4 subnets of equal size. Find network and broadcast address of the second subnet.
   * For 4 subnets, borrow 2 bits (2^2=4). So /18 prefix.
   * Network : 172.16.64.0/18
   * Broadcast : 172.16.127.255/18
5. 172.30.0.0/16 network. Divide into subnets of 1000 hosts each. Find the number of subnets possible.
   * For 1000 hosts, 10 host bits are needed.
   * So 6 bits can be borrowed.
   * So 64 subnets (2^6).
