Solved

Convert CIDR to IP

Posted on 2012-03-28
10
1,393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37778211
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
ID: 37778214
I'm actually trying to figure out how to do it myself, without a calculator.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37778248
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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
LVL 29

Accepted Solution

by:
Jan Springer earned 500 total points
ID: 37778317
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
ID: 37778321
Thanks Jesper... but could you explain how you put the /21 into binary a little more, if you can, please?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37778576
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 29

Expert Comment

by:Jan Springer
ID: 37778624
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
ID: 37778894
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
ID: 37779577
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
ID: 37780203
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Suggested Courses
Course of the Month5 days, 15 hours left to enroll

626 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