In this article I am explaining IPv4 subnetting in following two situations.

**1.** Subnetting when given a required number of networks [Example 1]

**2.** Subnetting when given a required number of hosts [Example 2]

**Note :** You need to have basics of IPv4 address types and basics of subnetting

**Example 1 :**

You have a Class C network range `210.20.1.0`

and need to break it into `20`

separate networks.

**Note :** Here you have the information about number of nerworks you needed.

**Solution : **

**Step 1:** Reserve required bits in natural subnet mask and thus find the subnet mask.

For that find exponentiated value of `2`

near to `20`

. You can check it with following table.

`2 ^ 0 = 1`

2 ^ 1 = 2

2 ^ 2 = 4

2 ^ 3 = 8

2 ^ 4 = 16

2 ^ 5 = 32

2 ^ 6 = 64

2 ^ 7 = 128

2 ^ 8 = 256

2 ^ 9 = 512

2 ^ 10 = 1024

2 ^ 11 = 2048

2 ^ 12 = 4096

2 ^ 13 = 8192

2 ^ 14 = 16384

2 ^ 15 = 32768

2 ^ 16 = 65536

2 ^ 17 = 131072

2 ^ 18 = 262144

2 ^ 19 = 524288

2 ^ 20 = 1048576

2 ^ 21 = 2097152

2 ^ 22 = 4194304

2 ^ 23 = 8388608

2 ^ 24 = 16777216

2 ^ 25 = 33554432

2 ^ 26 = 67108864

2 ^ 27 = 134217728

2 ^ 28 = 268435456

2 ^ 29 = 536870912

2 ^ 30 = 1073741824

2 ^ 31 = 2147483648

So the exponentiated value of `2 near 20 is 32. i.e. 2 ^ n = 32 and so n = 5`

Thus we found number of bits need to reserve in Natural Mask. i.e. 5

Note : Since we have the “number of networks” information, we need to reserve bits using 1’s starting from the first bit of host portion of the natural subnet mask.

`Mask [before reserving] = 11111111.11111111.11111111.00000000`

Mask [ after reserving] = 11111111.11111111.11111111.11111000

So in decimal it is `255.255.255.248`

**Step 2:** Find the “increment” number

“Increment” number is the last possible network bit in decimal form.

So here that network bit is the bit sourounded by square brackets.

`11111111.11111111.11111111.1111[1]000`

So, converting 1000 to decimal form will give you the “increment” number. It is 8.

**Step 3:** Use “increment” number to find network ranges.

Start with your given network address and add your increment to the subnetted octet.

`210.20.1.0`

210.20.1.8

210.20.1.16

210.20.1.24

210.20.1.32

210.20.1.40

210.20.1.48

etc ...

Fill in your end ranges, which is the last possible IP address before you start the next range.

`210.20.1.0 - 210.20.1.7`

210.20.1.8 - 210.20.1.15

210.20.1.16 - 210.20.1.23

etc ...

**Example 2 :**

You need to break the Class B private IP address range `187.19.0.0`

into as many networks as possible, but each network must have at least 300 hosts.

Note : Here you have the information about number of hosts needed in each nerwork.

**Solution : **

**Step 1:** Reserve required bits in natural subnet mask and thus find the subnet mask.

For that find exponentiated value of 2 near to 300. You can check it with following table.

`2 ^ 0 = 1`

2 ^ 1 = 2

2 ^ 2 = 4

2 ^ 3 = 8

2 ^ 4 = 16

2 ^ 5 = 32

2 ^ 6 = 64

2 ^ 7 = 128

2 ^ 8 = 256

2 ^ 9 = 512

2 ^ 10 = 1024

2 ^ 11 = 2048

2 ^ 12 = 4096

2 ^ 13 = 8192

2 ^ 14 = 16384

2 ^ 15 = 32768

2 ^ 16 = 65536

2 ^ 17 = 131072

2 ^ 18 = 262144

2 ^ 19 = 524288

2 ^ 20 = 1048576

2 ^ 21 = 2097152

2 ^ 22 = 4194304

2 ^ 23 = 8388608

2 ^ 24 = 16777216

2 ^ 25 = 33554432

2 ^ 26 = 67108864

2 ^ 27 = 134217728

2 ^ 28 = 268435456

2 ^ 29 = 536870912

2 ^ 30 = 1073741824

2 ^ 31 = 2147483648

So the exponentiated value of 2 near `300 is 512. i.e. 2 ^ n = 512 and so n = 9`

Thus we found number of bits need to reserve in Natural Mask. i.e. 9

Note : Since we have the number of hosts information, we need to reserve bits using 0’s starting from right.

`Mask [before reserving] = 11111111.11111111.00000000.00000000`

Mask [ after reserving] = 11111111.11111111.11111110.00000000

So in decimal it is `255.255.254.0`

**Step 2:** Find the “increment” number

“Increment” number is the last possible network bit in decimal form.

So here that network bit is the bit sourounded by square brackets.

`11111111.11111111.111111[1]0.00000000`

So, converting 10 to decimal form will give you the “increment” number. It is 2.

**Step 3:** Use “increment” number to find network ranges.

Start with your given network address and add your increment to the subnetted octet.

`187.19.0.0`

187.19.2.0

187.19.4.0

187.19.6.0

187.19.8.0

187.19.10.0

etc ...

Fill in your end ranges, which is the last possible IP address before you start the next range.

`187.19.0.0 - 187.19.1.255`

187.19.2.0 - 187.19.3.255

187.19.4.0 - 187.19.5.255

187.19.6.0 - 187.19.7.255

187.19.8.0 - 187.19.9.255

187.19.10.0 - 187.19.11.255

etc ...