Getting Started With VPC (Virtual Private Cloud) - Part Two

In this article, which is  part of series of articles around VPC, we are going to learn about IP addresses and will be covering the below topics:
  • Understanding IPv4 addressing
  • Understanding private IP ranges.
  • Understanding classful subnet mask.
  • Understanding CIDR notation.

UNDERSTANDING IPV4 ADDRESSING

 
In AWS, every EC2 instance we launch gets both a public and a private IP address. Now the private IP address gets created from the subnet of the availability zone under which we have created the EC2 instance.
  • If we don’t select the subnet while creating EC2 instance, then it will be assigned to the default subnet.
  • To understand IP address, we can say that it is the decimal representation of the binary numbers.
  • IP address consists of 4 Octets and a total of 32 bits.
 
Below is the complete range of IPv4 Address.
 
Regarding public IPs, they have their own range and they are managed by the Internet Service Providers.
 
AWS Cloud provider has a huge public IP address ranges and from that range we get our public IP for the EC2 instances.
 
Now let’s see the Private IP ranges.
 

UNDERSTANDING PRIVATE IP RANGES

 
The 32-bit IP address is divided into five sub-classes. These are,
  • Class A
  • Class B
  • Class C
  • Class D
  • Class E
Each of these classes has a valid range of IP addresses. Classes D and E are reserved for multicast and experimental purposes respectively. The order of bits in the first octet determines the classes of IP address.
 
Now let’s see the IP address ranges for each of the classes.
 
Class A 10.0.0.0 – 10.255.255.255
Class B 172.16.0.0 – 172.31.255.255
Class C 192.168.0.0 – 192.168.255.255
 
NOTE
We are going to design the subnets with the private IPs, not public IPs, because if we use public IPs then it may conflict with the public IPs provided by internet service provider.
 
 
There is a misconception that we use subnet mask 255.255.255.0 with Class C , 255.255.0.0 with Class B and 255.0.0.0 with Class A but this is not right;  we can use any subnet mask with any class.
 
Now let’s see what this subnet mask does to the IP address.
 
For example, if the IP address is 192.168.1.20  and subnet Mask is  255.255.255.0
 
Now we need to answer a few questions looking at the subnet mask.
  • What is the first IP or network address in this network?
  • What is the last IP or broadcast address in this network?
  • What is the gateway IP in this network?

SOLUTION

 
By looking at the subnet mask 255.255.255.0 we can see that first 3 octets are full.
 
So, the entire IP address range will start from 192.168.1.0 to 192.168.1.255 in this network.
 
What is the first IP or network address in this network?
 
First IP is also called network address and will be 192.168.1.0.
 
What is the last IP or broadcast address in this network?
 
Last IP is called broadcast address and will be 192.168.1.255.
 
What is the gateway IP in this network?
 
Next IP after First IP is assigned for the gateway and will be 192.168.1.1.
 
Thus, the actual usable IP address range would be from 192.168.1.2 to 192.168.1.254 .
 
Total Possible IP addresses in the network will be 0-255 = 256 IP addresses.
 
Let’s take another example, Example 2:
 
IP Address 172.16.0.0
Subnet mask 255.255.0.0
 
Similarly, as seen in the previous example, we can calculate the values as follows:
 
First IP (Network address) 172.16.0.0
 
Usable IP ranges
 
172.16.0.1,
172.16.0.2,
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
172.16.0.255,
172.16.1.0
172.16.1.1
172.16.1.2
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
172.16.1.255
172.16.2.0 and it will go on…till 172.16.255.254 
Last IP (Broadcast address)  172.16.255.255.
 
As the last 2 octets of subnet mask are free so we can fill that, and any octet starts from 0 and ends at 255.
 
Total possible IPs = 256*256 =65K approx. ,if we are going to use 255.255.0.0 subnet mask.
 
EXAMPLE 3
 
IP Address 10.0.0.1
Subnet mask 255.0.0.0
 
Now we can easily derive the values,
 
First IP (Network address) 10.0.0.0
Usable IP ranges
10.0.0.1 - 10.255.255.254
Last IP (Broadcast address) 10. 255. 255.255
Total possible IPs = 256*256*256 = 16777216
 
So now by looking at subnet mask we can tell all these things.
 
We can also use online IP subnet calculator as seen below.
 
 

UNDERSTANDING CIDR NOTATION

 
For Subnet mask 255.0.0.0, its binary conversion will be 11111111.00000000.00000000.00000000 out of all this binary format we have eight 1s, so CIDR notation will be CIDR = /8
 
Example 2
 
Subnet mask 255.255.0.0
 
Binary conversion 11111111. 11111111.00000000.00000000
CIDR = /16
 
Example 3
 
Subnet mask 255.255. 255.0
Binary conversion 11111111. 11111111. 11111111.00000000
CIDR = /24
 
Nowadays we have started using CIDR in place of writing complete subnet mask as 255.255. 255.0.
 

SUMMARY

 
In this article we learned the IPv4 addressing and saw subnets, and classful subnet mask CIDR notation. In the next article we will be using these concepts in practical implementation.
 
I hope you find this article helpful. Stay tuned for more … Cheers!!


Similar Articles