CIDR (Classless Inter Domain Routing) - vedratna/aws-learning GitHub Wiki

  • Format: xxx.xxx.xxx.xxx/xx. It is in two parts, first part is before / know as prefix and second part is after / known as suffix.

  • Prefix is IP address and as per the standard, each part of IP address (separated by .) is know as octet consist of 8 bits. Hence in total IP address consist 32 bits.

  • Suffix represents the no. of bits used for Network address. Hence if we deduct suffix number from 32, will get the no. of bits used for Host address. For example in 172.10.85.60/22, 22 bits are used for Network address, hence starting from left 11111111.11111111.111111xx.xxxxxxxx, all 1's are used for network address and hence remaining x that is 10 bits can be used for Host addresses.

  • In 172.10.85.60/22, we can use right most 10 bits for Host addresses that can have 2^10 = 1024 addresses. Out of 1024, two addresses are reserved for Network address and Broadcasting purpose respectively, hence 172.10.86.60/22 can accommodate at max 1022 hosts.

  • First address in the sequence is used as Network address and the last one is used for broadcasting.

  • Network and Broadcast address for 172.10.85.60/22:

  • First two octets are completely reserved hence 172.10 remains as it is. Now for third octet we have first 6 octets are reserved, use six ones and tow zero to represent it that is 11111100. Now covert 86 into binary, in 8 bit that would be 01010110. Now 11111100 AND 01010110 would be 01010100, in decimal it is 84. Hence our Network Address would be 172.10.84.0 and that would be the first Ip address in given CIDR block.

  • Now we know it can accommodate in total 1024 addresses. one octet can have 256 (0-255) numbers and 256 * 4 = 1024 that is 84.0-255, 85.0-255, 86.0-255, 87.0-255. Hence Broadcasting IP would be 172.10.87.255.

  • Other way to calculate the Broadcasting IP is by removing the reserved bit from the partially reserved octet. Here third octet with 11111100 is partially reserved. It has 6 bits reserved, after removing those 6 bits out of 8 bits, 2 bits remains. Now maximum number we can have with two bits is 11, in decimal it is 3. Now add 3 to least decimal of that octet in the given IP. that is 84 + 3 = 87. Hence 172.10.87.255 would be Broadcasting IP.

  • Network and Broadcast address for 172.10.60.16/29:

  • Left most 29 bits are reserved that is 11111111.11111111.11111111.11111xxx.

  • It can accommodate (32 - 29 = 3) 2^3 = 8 - 2 = 6 hosts.

  • First 3 octets are completely reserved hence 172.10.60 remains constant. We need to use 16 of fourth octet to find out Network and Broadcasting IPs.

  • 8 bit binary representation of 16 is 00010000.

  • Fourth octet has 5 bits reserved hence 11111000.

  • 11111000 AND 00010000 would be 00010000 that is 16 in decimal.

  • Hence Network IP address for this CIDR would be 172.10.60.16.

  • Broadcasting IP would be 16 + 8 = 23 (including 16), 172.10.60.23.

  • With other way, 3 bits are unreserved in fourth octet and maximum no. of 3 bits is 111 that is 7 in decimal. 16 + 7 = 23 hence 172.10.60.23

  • Network and Broadcast address for 192.168.60.55/20:

  • Left most 20 bits are reserved that is 11111111.11111111.1111xxxx.xxxxxxxx.

  • 32 - 20 = 12 bits are available for hosts, that can accommodate 2^12 - 2 = 4094 hosts

  • 60 = 00111100

  • 11110000 AND 00111100 = 00110000 = 48.

  • Hence Network Address = 192.168.48.0

  • Maximum number with unreserved bits on third octet = 1111 = 15

  • 48 + 15 = 63. Hence Broadcasting IP would be 192.168.63.255.

Refer this video for calculation explanation