The howtos cited explain it pretty well. If I have a 'net connection I just use:
http://www.subnet-calculator.com/cidr.php
If I have to calculate it manually for some reason (very rare), here's what I do...
Part 1
Keep in mind the following:
Code:
2(7) | 2(6) | 2(5) | 2(4) | 2(3) | 2(2) | 2(1) | 2(0)
-------------------------------------------------------
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
The top row is 2 (to the power of
n) in each column. e.g.: 2 * 2 * 2 * 2 * 2 * 2 * 2 == 128
If you don't follow that part, then read it again and figure it out. The rest of this won't make sense until you get that much.
Part 2
Next, look at each netmask octet and
convert it from decimal to binary.
Given the netmask 255.255.224.0:
- 255 == 11111111
- 255 == 11111111
- 224 == 11100000
- 0 == 00000000
So the netmask 255.255.255.224.0 in binary would be 11111111.11111111.11100000.00000000.
Understand so far? If not, re-read until you do, or the rest won't make sense.
Part 3
Remember that handy little chart from
Part 1? We're going to use the bottom row of it here to take a different look at our binary netmask.
First octet:
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
-------------------------------------------------------
1 1 1 1 1 1 1 1
Second octet:
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
-------------------------------------------------------
1 1 1 1 1 1 1 1
Third octet (this is where it starts to get interesting):
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
-------------------------------------------------------
1 1 1 0 0 0 0 0
Fourth octet:
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
-------------------------------------------------------
0 0 0 0 0 0 0 0
Notice how the
last column containing a '1' is third octet, 32 column? This means that our netmask breaks down IP networks into ranges of addresses 32 each. Thus, given the IP address 10.50.120.1/255.255.224.0, the ranges will look like:
- 10.50.0.0 - 10.50.31.255
- 10.50.32.0 - 10.50.63.255
- 10.50.64.0 - 10.50.95.255
- 10.50.96.0 - 10.50.127.255
- 10.50.128.0 - 10.50.159.255
- 10.50.160.0 - 10.50.191.255
- 10.50.192.0 - 10.50.223.255
- 10.50.224.0 - 10.50.255.0
Within that set of ranges, 10.50.120.1 is of course in 10.50.96.0 - 10.50.127.255. Note that the
first and
last addresses within a range may not actually be assigned to hosts. (The first is often the default router, and the last is usually the broadcast address.)
Free tip: Note that you can count (from left to right) the number of 1 values in your binary netmask to determine your CIDR notation netmask.
11111111 11111111 11100000 00000000 ... that's nineteen 1s, so your CIDR notation netmask is /19.
Your turn
Work through some examples on your own to make the process stick. Now that you know how to do it... you probably never will need to.
Aren't you glad you asked?