Solved

Convert CIDR to IP

Posted on 2012-03-28
10
1,277 Views
Last Modified: 2012-10-24
My apologies if this has been answered.

I'm having a hard time understanding how to turn, for example, 172.16.32.0/21 in to a subnet mask... I know it's not tough but for some reason, it's eluding me.

Any 'lamens' help would be much appreciated :).
0
Comment
Question by:GaleBeckwith
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
This calculator http://www.subnet-calculator.com/cidr.php seems to work right.  Enter the base IP (172.16.32.0) and then below that the mask bits (21) and it calculates the rest.
0
 

Author Comment

by:GaleBeckwith
Comment Utility
I'm actually trying to figure out how to do it myself, without a calculator.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Then this is a better explanation: http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing   If you take the IP address as 4 8-bit bytes, the mask number is the left-most bits, 21 in your case.  I don't think all combinations are valid though.
0
 
LVL 28

Accepted Solution

by:
Jan Springer earned 500 total points
Comment Utility
I find it's easiest when looking at the mask in binary with the offset starting at 0 (not 1):

/21 = 21 bits to the mask 11111111.11111111.11111000.00000000

1            1            1           1          1         1        1        1   =   11111111 = 255
-------------------------------------------------------------------
 128     64         32         16          8         0        0         0  =    248

128+64+32+16+8 = 248

/21 = 255.255.248.0
0
 

Author Comment

by:GaleBeckwith
Comment Utility
Thanks Jesper... but could you explain how you put the /21 into binary a little more, if you can, please?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
I'm curious what you are expecting.  What _jesper_ showed is the same as on the link I posted and is the way it is normally done.  There are a few rules and restrictions in addition but that is the 'math' to do it.
0
 
LVL 28

Expert Comment

by:Jan Springer
Comment Utility
There are 8 bits to each octet => 11111111

There are four octets that define the value of an IP address or netmask.

Add the binary bits from right to left with the value of the bit to the immediate left being double the amount of the bit to its right.                  1      1   1    1   1  1  1  1
                                                                                --------------------------------
There are a maximum of 255 bits to each octet => 128+64+32+16+8+4+2+1

(count the number of "1"s below)

/21 = 1 1 1 1 1 1 1 1     .     1 1 1 1 1 1 1 1     .      1 1 1 1 1 0 0 0                     .     0

                 255                     255                            128+64+32+16+8 = 248      .    0

                                            255.255.248.0

How many bits are remaining?  7 = 4+2+1.   This is also the number used in an inverse mask.  Add 7 to the 3rd octet and you will see the last usable number within that field that you may use within that /21.  Because you include the starting subnet boundary, you have a total of 8 /24s for your use.
0
 
LVL 11

Expert Comment

by:BillBondo
Comment Utility
Hope I remember this correctly.... I just count on my fingers. You are using 11 bits for your computers and 5 for the subnets. 11 should give you 2048 computers per subnet and 32 subnets. With 3 bits being used in the second octet, you would count 2-4-8 and subtract 8 from 256 and get 248.   Bit count goes on your fingers 2 4 8 16 32 64 128 256 .... Been a while since I took that ccna. So if I have it correct and using your address and I needed 500 users per subnet, I should have a mask of /23 or 255.255.254.0 giving me 512 users for 128 subnets.
0
 
LVL 17

Expert Comment

by:rochey2009
Comment Utility
Hi,

The /21 determines how many bits in the subnet mask are set to one from left to right as you write them down. After you've written down 21 consecutive one's, start writing consecutive zero's until you have 32 bits. (Break them up into 8 bits separated by a decimal point)

In binary this will be:

Subnet Mask = 11111111.11111111.11111000.00000000

Convert the binary to decimal:

Subnet Mask = 255.255.248.0
0
 
LVL 44

Expert Comment

by:Darr247
Comment Utility
And I'll add another $0.02 worth...

Given a starting address of 172.16.32.0 /21

Without a calculator, you count the total bits to convert from  'slash' format. e.g.
1111 1111 . 1111 1111 . 1111 1000 . 0000 0000 Subnet Mask = /21 (out of 32-bits total)
           255  .            255 .   3rd octet  .   4th octet


3rd octet in mask            times 256 (from the 4th octet - 0 through 255 = 256)
1111 1111 = /24  = 255   (1     *  256 =     256 IPs)  172.16.32.0 to 172.16.32.255
1111 1110 = /23  = 254   (2     *  256 =     512 IPs)  172.16.32.0 to 172.16.33.255
1111 1100 = /22  = 252   (4     *  256 =   1024 IPs)  172.16.32.0 to 172.16.35.255
1111 1000 = /21  = 248   (8     *  256 =   2048 IPs)  172.16.32.0 to 172.16.39.255
1111 0000 = /20  = 240   (16   *  256 =   4096 IPs)  172.16.32.0 to 172.16.47.255
1110 0000 = /19  = 224   (32   *  256 =   8192 IPs)  172.16.32.0 to 172.16.63.255
1100 0000 = /18  = 192   (64   *  256 = 16384 IPs)  172.16.0.0  to  172.16.63.255
1000 0000 = /17  = 128   (128 *  256 = 32768 IPs)  172.16.0.0  to  172.16.127.255
0000 0000 = /16  =     0   (256 *  256 = 65536 IPs)  172.16.0.0  to  172.16.255.255

Available IP addresses is always 2 less than possible, because one is reserved as the network identifier and one is reserved as the broadcast IP.

So, for the 172.16.32.0 /21 network, there are really only 2046 IPs available.

---
There are 10 kinds of people - those who think in binary, and those who don't.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now