Documente Academic
Documente Profesional
Documente Cultură
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
Host Bits
Each class has got certain properties and these are illustrated in a very brief manner below.
0
Network Bits
Host Bits
a)
b)
c)
d)
e)
f)
g)
10
Network Bits
a)
b)
c)
d)
e)
f)
Host Bits
110
Network Bits
Host
Bits
a)
b)
c)
d)
e)
f)
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
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.
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.
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
Length of subnet
mask, (N+S)
16
20
12
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)
Length of subnet
mask, (N+S)
16
12
28
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
Remainder Stage-1: 1
2. 12/2= 2*6+0;
Remainder Stage-2: 0
Remainder
at Stage(N-1)
Remainder
at Stage(N-2)
...
Remainder
at Stage2
Remainder
at Stage1
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.......!!!!!!!!!!!!!!!!!!!!!!!!!!