Understanding why we do things, the simple math behind a subnet mask and why we use certain IP ranges makes it, in my mind, simpler for the tech than memorizing numbers without a context.
BTW, 95% of 2 year IT graduates can't give you a definition of a default gateway or an example of when a network may have more than 1 gateway.
I posted the following as an answer on Quora a while back. I don't know if this is an appropriate place for it, but since we're discussing IP networking, I'll toss it up here.
* * * * *
Calculating IPv4 subnets can actually be quite easy, and you don't even need to use binary math. You probably won't even need a calculator or a special program. If you learn the principles I present below, you'll be able to do it in your head.
IPv4 Address FormatIPv4 addresses are made up of four octects separated by periods, or dots. An example is 192.33.31.65 -- one of the addresses that
www.quora.com resolves to. The numbers in the address are called octects because they are the decimal values of 8-bit binary words. Each binary digit (bit) represents a power of two.
The rightmost bit represents a value of 2
0 (1) and the leftmost bit a value of 2
7 (128). If all bits have a binary value of 1, then the value of the 8-bit word is 255. Here is a handy reference for the value of each bit:
2
0 = 1
2
1 = 2
2
2 = 4
2
3 = 8
2
4 = 16
2
5 = 32
2
6 = 64
2
7 = 128
2
8 = 256
(Yes, "two to the zeroth power equals one" is a legitimate mathematical construct. For that matter, "anything to the zeroth power" always equals one.)
Calculating powers of 2 is easy: each integer increase in the power doubles the result. 1+1=2, 2+2=4, 4+4=8, 8+8=16, and so on. The total number of addresses in a subnet must always be a power of 2.
How many addresses in the subnet?Since each octet of an IPv4 subnet has 256 possible values (0-255), 256 is a very important number and forms the basis for the rest of the math. We'll start with an easy question: how many addresses in a subnet if the mask is 255.255.255.248? We will ignore the first three octets for now and look at the last. Here is how easy it is: subtract 248 from 256. 256 minus 248 equals 8. There are 8 addresses available (including the network and broadcast addresses). The reverse also works: if I want to have a subnet with 16 addresses, what will the subnet mask be? 256 minus 16 equals 240. The subnet mask will be 255.255.255.240.
Now if we want to expand beyond a "class C" scope, it gets only a tiny bit more complicated: if our last octet is 0 and our third octet is, say, 240, then we do the math on the third octet and find that there would be 16 addresses. So we multiply 16 by 256 (the number of addresses in the last octet) to get 4,096. If both the last two octets are 0, then we take the subtraction result from the second octet (we'll say it's 16 again), multiply but 256 (addresses in the third octet), multiply again by 256 (addresses in the last octet) to get 1,048,576 addresses. Easy as that! (OK, so the reverse is a little more difficult. If we want a subnet with 1,048,576 addresses, we'll have to divide that number by 256 a couple of times to get a number we can subtract from 256.)
Network Address and Broadcast AddressNow that we know how to calculate the subnet mask, how do we figure out what the network address is? That's easy: it's always a multiple of the number of addresses in our subnet. So if we have 16 addresses in our subnet, the possible network addresses will be 0 (yes, 0 is a multiple of 16), 16, 32, 48, 64, and so on up to 240.
Where the network address is the first address in the subnet, the broadcast address is always the last address in the subnet.
CIDR NotationSo how about CIDR notation? How do translate that to and from an IPv4 address?
Remember our powers of two? Well, now we have another key number to remember besides 256: 32. Remember, CIDR notation describes the number of significant bits in the IPv4 address (where the significant bits are the leftmost, or unchanging bits in the subnet), and there are 32 bits in an IPv4 address, 8 for each octet. So if we have a subnet mask of 255.255.255.240, that is 16 addresses. If we look at our "powers of 2" table above, we see that 16 is two to the fourth power (2
4). So we subtract that power number -- 4 -- from 32 and get 28. Our CIDR notation for a subnet mask of 255.255.255.240, our CIDR notation is <network address>/28. And if we are given a /28, we subtract that (28) from 32 to get 4; raise 2 to that (4th) power (2
4) to get 16; then subtract that (16) from 256 to get 240; or 255.255.255.240.
How easy is that? Except for the "very large value of 2" (1,048,576), I did all that math IN MY HEAD AS I WAS TYPING THIS.