Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 22, 2020 08:30 pm GMT

CIDR - what the heck is it?

So you may or may not have heard about this CIDR - Class Inter Domain routing , ever wonder what is it or why is it even needed? In this post i have tried to oversimplify it by using my own formulas and stuff and and this can get really messy if you are not a network admin or hearing it for the first time!

What is CIDR

from wiki

"Classless Inter-Domain Routing (CIDR /sadr, s-/) is a method for allocating IP addresses and for IP routing. The Internet Engineering Task Force introduced CIDR in 1993 to replace the previous classful network addressing architecture on the Internet. Its goal was to slow the growth of routing tables on routers across the Internet, and to help slow the rapid exhaustion of IPv4 addresses.[1][2]"

IP in CIDR Notation

So CIDR is a method to write IP addresses, right! ok, so lets take an ip address, Like 8.8.8.8,
now this is a singleton ip address, meaning its just an ip address, however in CIDR you will use this notation - 8.8.8.8/32.. the first part "8.8.8.8" is called a prefix and the "/32" is a suffix..

But, what the heck is this 32? and what's the relevance here?

So all the ips have 4 parts (or dots) and each are 8 bits, overall 32 bits , now watch this 32 which will be used later.. The point to note here is that a "/32" suffix means, its a single ip address and anything less than that like a "/31" or "/16" or "/23" are a range of ip addresses.

More info -

Before that we need to touch base on few items like what are the classes of IP addresses.

Per techrepublic

IP Address Classes
There are five classes of IP addresses: A, B, C, D, and E. In the following sections, Ill discuss each class.

  • Class A addresses range from 0.0.0.0 to 127.255.255.255.
  • Class B network addresses range from 128.0.0.0 to 191.255.255.255.
  • Class C network addresses range from 192.0.0.0 to 223.255.255.255.
  • Class D IP addresses are reserved for multicasting.
  • Class E addresses are reserved for special use on the Internet.

    or -

    Now we can ignore D and E , as we will concentrate only on A, B and C. And since we are not talking about Network in general , we can jump to CIDR in full flow!

    CIDR notation

    So , any ipv4 address or range in this world can be depicted via CIDR using a prefix and suffix, so why is it needed?

    The previous classes of IP addresses presented more problems as the networks grew exponentially (or expanded) making it harder for organizations to adapt to IP address classes! , lets take an example of an large company, with wide range of servers in its network and all of them requiring an ip address and a class C ip address may not even fit.

    Enter CIDR for efficient subnetting , Example if the company has three tiers, each needing different sets of IP address, the CIDR notation might looks something like this

  • Web - 10.1.0.0/20
  • App- 10.1.0.0/23
  • DB- 10.1.0.0/25

    Now how many IP address does each have?

    Lets take web tier, we could see that this has a "/20" suffix, meaning the range is 4096 ip addresses.. wait what?! how?

    well, here is how :)

    The way i calculate the IP address from a CIDR range is like this..

            1) Subtract  20 from 32 = 12        2) What is 2^12 = 4096

    Or if you take /20 as x, do this

            1) x =20        2) y =32-x

    Answer = 2^y = 4096

    tada, there are 4096 ip addresses in /20 CIDR, but what are those ip address and what's the range..

    OK , part 2 -
    How many total ipv4 ips are there? like ex when we say 0.0.0.0/0, how many ips does it have ? /0 has 4,294,967,294 IP addresses = 2^32 ;)

    So if someone asks the range of /20, here is how i calculate that

         1) IP = 10.1.0.0/20 = 4096 ips     2) Now take this 4096/256 = 16 (256 is a constant - 0-255 ips)     3) 16-1 =15      4) The range is 10.1.<b>0.0</b> - 10.1.<b>15.255</b>

    So the ranges are like
    10.1.0.0 - 10.1.0.255
    10.1.1.0 - 10.1.1.255
    10.1.2.0 - 10.1.2.255
    .
    .
    .
    .
    10.1.15.0 - 10.1.15.255

    check the full listhere

    Formula
    1) x=4096

    2) y=256
    3) z=(4096/256)-1

       <b> Answer = 15  = range

    (note that this is a constant on my calculation and what if , say the x is lesser than y ;), check bottom of post)

    Now lets throw any ips and check..

  • App- 10.1.0.0/23 = 512 ip addresses / range 10.1.0.0 - 10.1.1.255
  • DB- 10.1.0.0/25 = 128 = 10.1.0.0 - 10.1.0.127

    So , if the list of IP addresses are greater than 256 we use the formula of y/x-1, if its below 256 , we use the calculation of Ip address -1

    Like 10.1.0.0/25 = 128 ip addresses and range is 10.1.0.(128-1)=10.1.0.127


  • Original Link: https://dev.to/viv/cidr-what-the-heck-is-it-220b

    Share this article:    Share on Facebook
    View Full Article

    Dev To

    An online community for sharing and discovering great ideas, having debates, and making friends

    More About this Source Visit Dev To