Sunteți pe pagina 1din 13

Subnetting Made Simple:

An Algorithmic Approach
By
Munmi Kakoty

21st century has been marked by rapid rise in packet based technologies. IP has been the
frontrunner in this field. We are gradually moving towards an all-packet based platform.
This paper aims at bringing to fore certain curious mathematical properties of the 32-bit
IPv4 structure. These properties can be put to good use in calculating:
a) Subnet Mask
b) IPs of subnets and hosts (esp. deeply embedded subnet and hosts of an arbitrarily
large network)
Before we delve into the technical details lets get an overview of the IPv4 32-bit structure
(not header structure!!).
What is an IPv4 address and why do we need it in first place?
IPv4 or IP version-4 address is a 32-bit dotted decimal number that is used for Layer-3
addressing i.e. to identify networks and hosts within the network at Layer-3 level. It is due
to IP addresses that we can route packets from one network to another.
Properties of IPv4 structure:
a) It is 32-bit long. This calculates to 232 addresses at our disposal.
b) The 32-bits are grouped into a group of 8-bits called an Octet. IPv4 has 4*Octets.
To understand subnetting we need to understand two approaches to classifying the IPv4
address space:
a) Classful addressing approach
b) Classless addressing approach or CIDR (Classless Inter Domain Routing)
Let us understand each of them step by step.
Classful Approach: This approach of addressing scheme divides the IPv4 address space into
classes. In other words IPv4 addresses are grouped into different groups otherwise known
as classes. This approach defines 5 classes:
a)
b)
c)
d)
e)

Class
Class
Class
Class
Class

A
B
C
D
E

2-level hierarchy model:


In this approach the 32-bit address space is divided into two-level hierarchy: Network Bits
and Host Bits
Network Bits

Host Bits

Each class has got certain properties and these are illustrated in a very brief manner below.

Class A: The properties of the Class A IP range is highlighted below:

0
Network Bits

Host Bits

a)
b)
c)
d)
e)
f)
g)

Network Bits, n = 8-bits


Host Bits, h = 24-bits
First bit of the network part is 0.
Number of networks= 28 or 256
Number of hosts= 224 or 16777216
IP address range= 0.x.x.x to 127.x.x.x
First network of Class A is 0.0.0.0 or All-zero network. This is a reserved network
hence cant be used.
h) The network 127.x.x.x is used for loopback testing and hence cant be used for
normal addressing.
i) Usable IP address range= 1.x.x.x to 126.x.x.x

Class B: The properties of the Class B IP range is highlighted below:

10
Network Bits
a)
b)
c)
d)
e)
f)

Network Bits, n = 16-bits


Host Bits, h = 16-bits
First two bits of the network part are 1 0.
Number of networks= 216 or 65536
Number of hosts= 216 or 65536
IP address range= 128.0.x.x to 191.0.x.x

Host Bits

Class C: The properties of the Class C IP range is highlighted below:

110
Network Bits

Host

Bits
a)
b)
c)
d)
e)
f)

Network Bits, n = 24-bits


Host Bits, h = 8-bits
First three bits of the network part are 110.
Number of networks= 224 or 16777216
Number of hosts= 28 or 256
IP address range= 128.0.x.x to 191.0.x.x

Class D is used for multicasting and Class E is reserved. These classes will not be discussed
in details.
Properties of Class D:
a) First 4-bits of the 32-bits is 1110
b) No network or Host part defined
Properties of Class E:
a) First 4-bits of the 32-bits is 1111
b) No network or Host part defined

Limitations of classful addressing approach:


The classful addressing approach has the following major limitations:
a) Class A contains small number of network with a relatively large number of hosts
while Class C contains large number of network with relatively small number of
hosts. This sort of size extremities has led to lot of wastage of IPs and rapid
depletion of the intermediate sized Class B network.
b) Addressing system is quite rigid. Say if you have 100 hosts one has to buy a Class C
network even leading to wastage of 156 IPs if there is no utilization of the same in
near future.

3-level hierarchy model:


In this model another level of hierarchy namely subnet bits (borrowed from host bits) are
added. This level leads to:
a) Addressing becomes more flexible as we can now break a large network into smaller
network of our requirement.
b) Wastage of IP is minimized.
c) Introduction of subnet mask.
Network Bits

Subnetwork Bits

Host Bits

What is a subnet?
A subnetwork, or subnet, is a logically visible, distinctly addressed part of a single IP
network.
What is a subnet mask?
Also called netmask. A customer-configurable value for increasing the number of bits within
an IPv4 address that are used for network identification. Use of a subnet mask allows one IP
address to be subdivided into multiple networks (called subnets). Within a subnet mask, the
bits set to 1 specify the portion of the address used to identify networks, while the bits set
to 0 identify the hosts.
Default subnet masks: There are three default subnet masks corresponding to the three
classes. They are:
a) Class A Subnet Mask represented by 255.0.0.0
b) Class B Subnet Mask represented by 255.255.0.0
c) Class C Subnet Mask represented by 255.255.255.0
The standard subnet mask is only for reference purpose. Two approaches for exploiting the
advantage 3-level hierarchical addressing scheme are used:
a) Fixed Length Subnet Masking or FLSM
b) Variable Length Subnet Masking or VLSM
FLSM is based on classful addressing approach while VLSM is based on CIDR or classless
addressing approach.

Brief description of FLSM and VLSM is presented for understanding.


FLSM or Fixed Length Subnet Masking:
FLSM is based on the philosophy one-size-fits-all design. FLSM breaks a network into
equal sized subnet. FLSM is applicable to classful networks i.e. Class A, B & C.
To illustrate lets take a Class C network 192.9.1.0 255.255.255.0. Using FLSM method the
number of subnet bits, S= 2, 3, 4, 5, & 6.
Subnet Bits, S

FLSM Subnet
Mask

No. Of
subnets, 2N

Host Bits, H

No. of usable
hosts, 2H-2

255.255.255.192

62

255.255.255.224

30

255.255.255.240

16

14

255.255.255.248

32

255.255.255.252

64

Say if we want 31 hosts/subnet, from the table we find that we have to use FLSM value
255.255.255.192 and break the network into 4 subnet containing 62 hosts each. But we
require only 31 hosts/subnet wastage of 31 host addresses/subnet. Thus FLSM introduces
flexibility in addressing but doesnt help much to avoid wastage of IP addresses.
The solution- VLSM or Variable Length Subnet Masking was introduced.
VLSM or Variable Length Subnet Masking:
A Variable Length Subnet Mask (VLSM) is a means of allocating IP addressing resources to
subnets according to their individual need rather than some general network-wide rule.
VLSM is based on CIDR or Classless Inter Domain Routing. CIDR eliminates the concept of
class. The CIDR notation table is given below.

CIDR Notation Table:

Subnet Mask

CIDR
Prefix

Total IP's

Usable IP's

255.255.255.255

/32

255.255.255.254

/31

255.255.255.252

/30

255.255.255.248

/29

255.255.255.240

/28

16

14

255.255.255.224

/27

32

30

255.255.255.192

/26

64

62

255.255.255.128

/25

128

126

255.255.255.0

/24

256

254

255.255.254.0

/23

512

510

255.255.252.0

/22

1024

1022

255.255.248.0

/21

2048

2046

255.255.240.0

/20

4096

4094

255.255.224.0

/19

8192

8190

255.255.192.0

/18

16,384

16,382

255.255.128.0

/17

32,768

32,766

255.255.0.0

/16

65,536

65,534

255.254.0.0

/15

131,072

131,070

255.252.0.0

/14

262,144

262,142

255.248.0.0

/13

524,288

524,286

255.240.0.0

/12

1,048,576

1,048,574

255.224.0.0

/11

2,097,152

2,097,150

255.192.0.0

/10

4,194,304

4,194,302

255.128.0.0

/9

8,388,608

8,388,606

255.0.0.0

/8

16,777,216

16,777,214

254.0.0.0

/7

33,554,432

33,554,430

252.0.0.0

/6

67,108,864

67,108,862

248.0.0.0

/5

134,217,728

134,217,726

240.0.0.0

/4

268,435,456

268,435,454

224.0.0.0

/3

536,870,912

536,870,910

192.0.0.0

/2

1,073,741,824

1,073,741,822

128.0.0.0

/1

2,147,483,648

2,147,483,646

0.0.0.0

/0

4,294,967,296

4,294,967,294

Getting hands dirty..


Lets solve a problem to get up close and personal with VLSM and CIDR.
*Remember the network bits do not change.
Base IP: 140.25.0.0/16 (first 16-bits belong to network)
a) Problem: Break the base network into 16 equally sized sub-networks.
Solution:
Network bits, N=16
No. of subnets required=16
Nearest power of 2 greater than or equal to 16 is 24>=16
Therefore no. of subnet bits, S=4
Length of subnet mask, (N+S) = (16+4) =20
CIDR Notation= /20
No. of host bits, H= [32-(N+S)] = [32-20] = 12
Network Bits, (N)

Subnet Bits, (S)

Length of subnet
mask, (N+S)

Host Bits, [32(N+S)]

16

20

12

Base Network: 10001100.00011001 .00000000.00000000 = 140.25.0.0/16


Subnet #0: 10001100.00011001.0000 0000.00000000 = 140.25.0.0/20
Subnet #1: 10001100.00011001.0001 0000.00000000 = 140.25.16.0/20
Subnet #2: 10001100.00011001.0010 0000.00000000 = 140.25.32.0/20
Subnet #3: 10001100.00011001.0011 0000.00000000 = 140.25.48.0/20
Subnet #4: 10001100.00011001.0100 0000.00000000 = 140.25.64.0/20
Subnet #5: 10001100.00011001.0101 0000.00000000 = 140.25.80.0/20
Subnet #6: 10001100.00011001.0110 0000.00000000 = 140.25.96.0/20
Subnet #7: 10001100.00011001.0111 0000.00000000 = 140.25.112.0/20
Subnet #8: 10001100.00011001.1000 0000.00000000 = 140.25.128.0/20
Subnet #9: 10001100.00011001.1001 0000.00000000 = 140.25.144.0/20
Subnet #10: 10001100.00011001.1010 0000.00000000 = 140.25.160.0/20
Subnet #11: 10001100.00011001.1011 0000.00000000 = 140.25.176.0/20
Subnet #12: 10001100.00011001.1100 0000.00000000 = 140.25.192.0/20
Subnet #13: 10001100.00011001.1101 0000.00000000 = 140.25.208.0/20
Subnet #14: 10001100.00011001.1110 0000.00000000 = 140.25.224.0/20
Subnet #15: 10001100.00011001.1111 0000.00000000 = 140.25.240.0/20

b) Problem: Break the base network in such a way that there are 16 hosts/subnet.
Solution:
Network bits, N=16
No. of hosts per subnet=16
Nearest power of 2 greater than or equal to 16 is 24>=16
Therefore no. of host bits, H=4
No. of subnet bits, S= [32-(N+H)] = [32-20] = 12
Length of subnet mask, (N+S) = (16+12) =28
CIDR Notation= /28
Network Bits, (N)

Subnet Bits, [32(N+H)]

Length of subnet
mask, (N+S)

Host Bits, (H)

16

12

28

Base Network: 10001100.00011001 .00000000.00000000 = 140.25.0.0/16


Subnet #0: 10001100.00011001.0000 0000.00000000 = 140.25.0.0/28
Subnet #1: 10001100.00011001.0000 0000.00010000 = 140.25.0.16/28
Subnet #2: 10001100.00011001.0000 0000.00100000 = 140.25.0.32/28
Subnet #3: 10001100.00011001.0000 0000.00110000 = 140.25.0.48/28
:
:
:
Subnet#268435454: 10001100.00011001.1111 1111.11100000 = 140.25.0.48/28
Subnet # 268435455: 10001100.00011001.1111 1111.11110000 = 140.25.255.240/28

So we have got the formulae:


1) If number of subnets are specified
Network Bit = N
Subnet Bits = S such that 2S>= (No. of required subnets)
Length of subnet = (N+S)
CIDR notation = / (N+S)
Host Bits, H = [32-(N+S)] and No. of usable host IP = (2H-2)
2) If number of hosts are specified
Network Bit = N
Host Bits = H such that 2H>= (No. of required hosts)
Subnet Bits, S = [32-(N+H)]
No. of subnet = 2S
Length of subnet = (N+S)
CIDR notation = / (N+S)
The method described above to find the subnets is known as Binary Approach.
c) Problem: Define the hosts for Subnet#1 obtained in problem (b).
Solution:
Subnet #1: 10001100.00011001.0000 0000.00010000 = 140.25.0.16/28
Host#1: 10001100.00011001.0000 0000.00010001 = 140.25.0.17/28
Host#2: 10001100.00011001.0000 0000.00010010 = 140.25.0.18/28
:
Host#32: 10001100.00011001.0000 0000.00011111 = 140.25.0.31/28
The method applied in solving the above problems can be termed as Binary approach. This
approach is highly recommendable if you are new to subnetting. This method though has a
disadvantage: Its a bit slow in case of locating a subnet or host that is deeply embedded.
For this purpose a new faster algorithm has been developed based on the shifting of octets.
These will be introduced later. Lets have a brief tryst with binary numbers.

Binary numbers:
Binary or Base-2 numbers are denoted by 1 and 0. Any number can be represented by a
string of 1s and 0s. The place values from left to right are in the range 2N-1*[0, 1], where N
belongs to [0, 1, 2, 3n] i.e. to represent say the string 11001 in decimal we have:
(20*1+21*0+22*0+23*1+24*1) [Bits from left to right]
= 25
Powers

N-1

Place
Value

2N-1

26

25

24

23

22

21

20

Converting a decimal number into binary number:


Say we want to convert (25)10 to (25)2 so how do we do it???
*(N)b the subscript, b denotes the base and N denotes the number
Divide (25)10 by 2 repeatedly till the dividend is 1 or 0 and record the remainders obtained
in each division stage and then arrange them in reverse order to give (25)2.
1. 25/2= 2*12+1;

Remainder Stage-1: 1

2. 12/2= 2*6+0;

Remainder Stage-2: 0

3. 6/2= 2*3+0; Remainder Stage-3: 0


4. 3/2= 2*1+1; Remainder Stage-4: 1
5. Dividend= 1
Thus the (25)2 is 11001 the bits arranged in reverse order.
Generalizing the process of arranging the bits:
0 or 1

Remainder
at Stage(N-1)

Remainder
at Stage(N-2)

...

Remainder
at Stage2

Remainder
at Stage1

In the above example of converting (25)10 to (25)2:


0 or 1

Remainder

Remainder

Remainder

Remainder

Stage-4

Stage-3

Stage-2

Stage-1

For elaborate reference please refer any books on binary mathematics or just Google!!!!!!

Examples:
1) Address: 192.9.1.0/24
N = 24, S = 4 & H = 4
CIDR notation = / (N+S) = / (24+4) = /28
Subnet-0#192.9.1.0000 0000 = 192.9.1.0/28
Subnet-1#192.9.1.0001 0000 = 192.9.1.16/28
:
Subnet-15#192.9.1.1111 0000 = 192.9.1.240/28
Host-2 of Subnet-1#192.9.1.0001 0010 = 192.9.1.18/28

2) Address: 172.1.0.0/16
N = 16, S = 7 & H = 9
CIDR notation = / (N+S) = / (16+7) = /23
Subnet-0#172.1.0000 0000.0000 0000 = 172.1.0.0/23
Subnet-1#172.1.0000 0010.0000 0000 = 172.1.2.0/23
:
Subnet-127#172.1.1111 1110.0000 0000 = 172.1.254.0/23
Host-2 of Subnet-1#172.1.0000 0010.0001 0010 = 172.1.2.2/23

3) Address: 10.0.0.0/8
N = 8, S = 7 & H = 17
CIDR notation = / (N+S) = / (8+7) = /15
Subnet-0#10.0000 0000.0000 0000.0000 0000 = 10.0.0.0/15
Subnet-1#10.0000 0010. 0000 0000.0000 0000 = 10.2.0.0/15
:
Subnet-127#10.1111 1110. 0000 0000.0000 0000 = 10.254.0.0/15
Host-32769 of Subnet-1#10.0000 0010. 1000 0000.0000 0001 = 10.2.128.1/15

Address: 10.0.0.0/8
N = 8, S = 3 & H = 21
CIDR notation = / (N+S) = / (8+3) = /11
Subnet-0#10.0000 0000.0000 0000.0000 0000 = 10.0.0.0/15
Subnet-1#10.0010 0000. 0000 0000.0000 0000 = 10.32.0.0/15
:
Subnet-7#10.1110 0000. 0000 0000.0000 0000 = 10.224.0.0/15
Host-524289 of Subnet-1#10.0010 1000. 000 0000.0000 0001 = 10.40.0.1/15
Readers can try out few more problems on their own applying the method. So happy
subnetting.......!!!!!!!!!!!!!!!!!!!!!!!!!!

S-ar putea să vă placă și