Hagbart Celine
Hagbart Celine

Reputation: 470

Calculate Subnetmask from IP range

This was one task I had as homework I just can't seem to understand. And my teacher is having a hard time explaining it to class. So here I am:

The problem: What is the subnet mask of following host-address range? 99.224.0.1 - 99.239.255.254

My solution (or as far as I got) First i wrote down the IPs in binary:

99.224.0.1
01100011.11100000.00000000.00000001
99.239.255.254
01100011.11101111.11111111.11111110

What I know is this is a A class network. And I thought it must have something to do with the difference in the bits, so I started to compare. (highest first)

01100011.11101111.11111111.11111110 
01100011.11100000.00000000.00000001 (diff)
-----------------------------------
00000000.00001111.11111111.11111111

I ignored the last bit, because of the network / broadcast address.

Now I can turn it around and have my subnet mask?:

11111111.11110000.00000000.00000000
255.240.0.0

My question is: Is my approach correct? Is there an easier way to do it (by hand, or calc)?

If I'm very far from the correct way to do it, could someone help me understand?

Thanks for any help.

Upvotes: 0

Views: 745

Answers (1)

Sander Steffann
Sander Steffann

Reputation: 9978

Your answer is correct, except that classful addresses don't exist anymore. The internet moved to Classless Inter-Domain Routing (CIDR) in 1993 so your terminology is a bit outdated ;)

IP networking these days works with routing prefixes. A prefix is a range of IP addresses defined by the first address in that range and the number of fixed bits at the start of the address. Your example shows this nicely.

Your example range is 99.224.0.1 - 99.239.255.254. Actually it is 99.224.0.0 - 99.239.255.255 because when used on a subnet the first and last addresses are reserved (but still part of the subnet and prefix).

The first address in the prefix we already have: 99.224.0.0. You can see the prefix length from your binary calculation (slightly modified):

01100011.11101111.11111111.11111111
01100011.11100000.00000000.00000000
----------------------------------- (xor)
00000000.00001111.11111111.11111111
----------------------------------- (not)
11111111.11110000.00000000.00000000

Just count the number of 1s at the beginning: 12. So your prefix is 99.224.0.0/12. This prefix covers all addresses that match 01100011.1110****.********.********.

When writing the prefix length down as a subnet mask you indeed get 255.240.0.0.


A little off-topic here because it is about networking and not about the algorithm to calculate the subnet mask, but maybe helpful: an example of how you can plan network addressing:

Lets say that for my office building I get IP addresses 192.0.2.0/24 (that is 192.0.2.0 - 192.0.2.255, subnet mask 255.255.255.0, 256 addresses). I need 50 addresses for servers, 100 addresses for employee devices and 40 addresses for guests.

Because addressing works with prefixes everything you get is a power of 2. If you use a /24 you have a prefix with 256 addresses. The full address is 32 bits, the first 24 are fixed so you have 8 bits left to use. 28 = 256. If you use a /25 you have a prefix 128 addresses, a /26 has 64 addresses etc.

That way you can also split up a prefix. 192.0.2.0/24 can be split up into 192.0.2.0/25 and 192.0.2.128/25. And those can be split again and again until you have a prefix that covers only a single address: a /32.

back to the example. To get (at least) 50 addresses for the servers I need to round up to the next power of 2. That is 26 = 64. To have that many addresses I need a /26 prefix. For the client devices I need to round up to 128 (27) so we need a /25. For the guests the next power of 2 is 64 (26) so a /26.

So we need to split up out /24 into a /25 and two /26s. One possible solution is:

Client devices:  192.0.2.0/25
Servers:         192.0.2.128/26
Guests:          192.0.2.192/26

Once we configure these subnets on our devices the first and last address of each subnet become special (the network and broadcast address) so we can use these ranges for our devices:

Client devices:  192.0.2.1   - 192.0.2.126
Servers:         192.0.2.129 - 192.0.2.190
Guests:          192.0.2.193 - 192.0.2.254

Upvotes: 2

Related Questions