# IPv4 Subnetting

## IPv4 & Subnetting

The IPv4 Addressing is done as follow

•  32 bits are divided into 4 octet as decimal notation

First octet   Second       Third           Fourth

|               |                     |                          |

________   ________  ________  ________

01010101 .00000101 .10111111 .00000001

Binary to Decimal Conversion

Total 8 bits, Value will be 0’s & 1’s i.e., 28 =256 Combination

27      26      25      24      23      22      21      20

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 Range is

0.0.0.0 To 255.255.255.255

• IP Addressing Scheme is divided into 5 Classes
• Class A
• Class B      ——-> for  LAN & WAN
• Class C
• Class D   —————> For Multicasting
• Class E   ————— >Research & Development
• Priority Bits

To identify the range of each class bit called Priority bit is used

Priority bit are the left most bit in the First Octet of IP Address.

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

• Class A Range

The First bit of First Octet is reserved for Priority Bit

0xxxxxxx. xxxxxxxx. xxxxxxxx . xxxxxxxx

27      26      25      24      23      22      21      20

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

|

|

|

0       1       1       1       1       1       1       1       =        127

Class A Range is from 0.0.0.0 to 127.255.255.255

• Class B Range

The First two bits of First Octet is reserved for Priority Bit

10xxxxxx . xxxxxxxx . xxxxxxxx . xxxxxxxx

27      26      25      24      23      22      21      20

1       0       0       0       0       0       0       0       =        128

1       0       0       0       0       0       0       1       =        129

1       0       0       0       0       0       1       0       =        130

1       0       0       0       0       0       1       1       =        131

1       0       0       0       0       1       0       0       =        132

|

|

|

1    0       1       1       1       1       1       1       =        191

Class B Range is   from 128.0.0.0 to 191.255.255.255

• Class C Range

The First three bits of First Octet is reserved for Priority Bit

110xxxxx . xxxxxxxx . xxxxxxxx . xxxxxxxx

27      26      25      24      23      22      21      20

1       1       0       0       0       0       0       0       =        192

1       1       0       0       0       0       0       1       =        193

1       1       0       0       0       0       1       0       =        194

1       1       0       0       0       0       1       1       =        195

1       1       0       0       0       1       0       0       =        196

|

|

|

1       1       0       1       1       1       1       1       =        223

Class C Range is   from 192.0.0.0 to 223.255.255.255

• Class D Range

The First four bits of First Octet is reserved for Priority Bit

1110xxxx . xxxxxxxx . xxxxxxxx . xxxxxxxx

27      26      25      24      23      22      21      20

1       1       1       0       0       0       0       0       =        224

1       1       1       0       0       0       0       1       =        225

1       1       1       0       0       0       1       0       =        226

1       1       1       0       0       0       1       1       =        227

1       1       1       0       0       1       0       0       =        228

|

|

|

1       1       1       0       1       1       1       1       =        239

Class D Range is   from 224.0.0.0 to 239.255.255.255

• Class E Range

The First four bits of First Octet is reserved for Priority Bit

1111xxxx . xxxxxxxx . xxxxxxxx . xxxxxxxx

27      26      25      24      23      22      21      20

1       1       1       1       0       0       0       0       =        240

1       1       1       1       0       0       0       1       =        241

1       1       1       1       0       0       1       0       =        242

1       1       1       1       0       0       1       1       =        243

1       1       1       1       0       1       0       0       =        244

|

|

|

1       1       1       1       1       1       1       1       =        255

Class E Range is   from 240.0.0.0 to 255.255.255.255

There are certain addresses in each class of IP Address that are reserved for LAN (Local Area Network). These addresses are called Private address.

They are used for Home & Office network & are not used in Internet Live (Public) Address.

Class A Private Address is: 10.0.0.0 to 10.255.255.255

Class B Private Address is: 172.16.0.0 to 172.31.255.255

Class C Private Address is: 192.168.0.0 to 192.168.255.255

IP Address on each class is divided into Network & Host Portion

Class a is written as: N.H.H.H

(For example Class A, IP Address: 10.0.0.1, where 10 is N & rest is H,          means 10.0.0.1 belong to 10.0.0.0 network)

Class B is written as:   N.N.H.H

(For example Class B IP Address: 172.1.0.1, where 172, 1 is N & rest is H, means 172.1.0.1 belong to 172.1.0.0 network)

Class C is written as:   N.N.N.H

(For example Class C IP Address: 192.168.10.1, where 192,168,10 is N & rest is H , means 192.168.10.1 belong to 192.168.10.0 network)

Where N= Network Bits & H = Host Bits

• Class A No. of Networks & Hosts

Class A Octet Format is N.H.H.H

Network Bits: 8    Host Bits: 24    (total 32 bit)

No. of Networks

= 28-1 (-1 is priority bits of Class A)

= 27

= 128-2 (-2 is for 0 & 127 Broadcast network)

= 126 Networks

No. Of Hosts

= 224 – 2 (-2 is for network IP address)

= 16777216 – 2

= 16777214 Hosts/Network

The Possible Network & Hosts in Class A are

126 Networks

&   16777214 Hosts/Network

• Class B No. of Networks & Hosts

Class B Octet Format is N.N.H.H

Network Bits: 16    Host Bits: 16    (total 32 bit)

No. of Networks

= 216-2 (-2 is priority bits of Class B)

= 214

= 16384 Networks

No. Of Hosts

= 216 – 2 (-2 is for network IP address)

= 65536 – 2

= 65534 Hosts/Network

• Class C No. of Networks & Hosts

Class C Octet Format is N.N.N.H

Network Bits: 24    Host Bits: 8    (total 32 bit)

No. of Networks

= 224-3 (-3 is priority bits of Class C)

= 221

= 2097152 Networks

No. Of Hosts

= 28 – 2 (-2 is for network IP address)

= 256 – 2

= 254 Hosts/Network

The Possible Network & Hosts in Class C are

2097152 Networks

&   254 Hosts/Network

The Possible Network & Hosts in Class B are

16384 Networks

&   65534 Hosts/Network

• Network Address: It is Represented by all bits ZERO in Host portion of the address.

Example: IP Address: 192.168.10.20   : it is class C IP address & its Octet format is N.N.N.H   now for network address making Host bit ZERO, so its network address will be 192.168.10.0 respectively.

Example: IP Address: 192.168.10.20   : it is class C IP address & its Octet format is N.N.N.H   now for network address making Host bit ONE, so its Broadcast address will be 192.168.10.255 respectively.

• Subnet Mask Differentiates the Network Portion & Host Portion.
• Subnet Mask is given for Host Identification of Network ID
• To represent subnet mask put all bits ONE in Network Portion & all bits ZERO in Host Portion.
• Example is shown below
• Class A : N.H.H.H

11111111.00000000.00000000.00000000

Default Subnet Mask of Class A is : 255.0.0.0

• Class B : N.N.H.H

11111111.11111111.00000000.00000000

Default Subnet Mask of Class B is : 255.255.0.0

• Class C : N.N.N.H

11111111.11111111.11111111.00000000

Default Subnet Mask of Class C is : 255.255.255.0

How Does Subnet Mask Work, means how it differentiates Network & Host Bits

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

It Gives the Network Address of IP Address & Differentiates Host Bits.

• Sub netting
• Sub netting means dividing one network into multiple networks.
• Converting host bit to network bits
• Sub netting is also called FIXED LENGHTH SUBNET MASK
• Sub netting is done in three ways
1. 1.    Requirement of networks
2. 2.    Requirement of hosts
3. 3.    CIDR notation

Example of Sub netting

Consider IP Address : 192.168.1.1 need to be subnetted to 5 Network

Octet format is: N.N.N.H

Default Gateway: 255.255.255.0

Sub netting is converting Host bit to required network bit.

We need 5 networks of these IP address

Means 2s = 5

Value of s > 2 taking next value, s=3 (where s=subnet bit)

23 = 6 Subnets

Now IP format will be as below

N+S+H

192.168.1.0

11000000.10101000.00000001.00000000

nnnnnnnn.nnnnnnnn.nnnnnnnn.hhhhhhh

After sub netting

nnnnnnnn.nnnnnnnn.nnnnnnnn.ssshhhhh

No. of host per subnet

= 25 -2

= 30 Hosts/Subnets

IP address range of 192.168.1.1 will be

1 subnet = 192.168.1.0 to 192.168.1.31

2 subnet = 192.168.1.32 to 192.168.1.63

3 subnet = 192.168.1.64 to 192.168.1.95

4 subnet = 192.168.1.96 to 192.168.1.127

5 subnet = 192.168.1.128 to 192.168.1.159

6 subnet = 192.168.1.160 to 192.168.1.191

New Subnet mask will be: 255.255.255.224

It is done when there are different needs of IP address.

Consider IP address 192.168.1.1 is to be used to create three department & need to host in each department is shown below

Department A: 20 hosts

Department B: 50 Hosts

Department C: 100 hosts

For Department A: No. of Host required 20

No. of host bit to be kept is =5

New subnet mask for Department A will be= 255.255.255.224

For Department B: No. of Host required 50

No. of host bit to be kept is =6

New subnet mask for Department B will be= 255.255.255.192

For Department C: No. of Host required 100

No. of host bit to be kept is =7

New subnet mask for Department C will be= 255.255.255.128

As we have seen in above calculations that all department have different subnet mask.

IP Range for Department A will be

192.168.1.0 to 192.168.1.31

IP Range for Department B will be

192.168.1.32 to 192.168.1.95

IP Range for Department C will be

192.168.1.96 to 192.168.1.224

• Gateway

Gateway connects two networks. From which host from one network can connect to host of another network through gateway. Gateway is explained in below figure As shown in above figure that HOST A i.e., 10.0.0.1 have to use 10.0.0.20 as Default Gateway to connect to 15.0.0.0 network. Similarly HOST B i.e., 20.0.0.1 has to use 20.0.0.20 as Default Gateway to connect 15.0.0.0 network.