IPv4 address structure:
- It is a 32-bit long value
- In binary, it is a 32-bit long string of ones and zeros.
It has 4 octets, each octet 8-bit long string of ones and zeros
- In decimal format, it consists of 4 decimal numbers separated by a dot.
5 classes of IPv4
The class of an IP address is determined by the first octet.
Class A IP address has the first octet starting from 0, class B starts from 0+128 = 128. Class C starts from 0+128+64=192. Class D starts from 0+128+64+32=224. Class E starts from 0+128+64+32+16=240.
Class A ends at 127, which can be inferred from the starting end of Class B. Similarly Class B ends at 191, Class C ends at 223, Class D at 239, and Class E at 255.
First Octet in Decimal
The pattern to remember the binary representation is clearly visible from this picture.
We simply copy the first octet from the 2nd column and everyone ends at x.255.255.255. Where x is the octet value.
There is a pattern clearly visible from the picture below for default subnet masks up to class C. We don’t have subnet masks for Class D and E.
# of hosts per Network ID & # of networks
h = 2x -2
h is the no. of hosts; x is the number of zeros in the binary representation of the IP address.
n = 2y
n is the no. of networks, and y is the no. of ones in the binary representation of the IP address. Thus, we get: