How can you calculate IP address subnet ranges? [closed] - networking

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
If you're given:
Number of needed subnets: 2
Network Address: 195.223.50.0
I can answer the following:
Address Class: C
Default Subnet Mask: 255.255.255.0
Custom Subnet Mask: 255.255.255.192
Total number of subnets: 2^2 = 4
Total number of host addresses: 2^6 (8-2 = 6)
Number of usable addresses: 2^6 -2
Number of bits borrowed: 2
BUT.... if I'm asked....
What is the 3rd subnet range?
What is the subnet number for the 2nd subnet?
What is the subnet broadcast address for the 1st subnet?
What are the assignable addresses for the 3rd subnet?
How would I answer these... All I remember from the procedure is to look at the last number in the Custom subnet mask (192) and do 256 - 192 to get 64 and then use 64 to increment something. But I'm not sure what each question is asking. Please help, and explain step by step for each question.
Also, what would be different if I was faced with the Address Class of B in this situation?

this really isn't a programming question, and we generally don't use Classful Addressing (A,B,C,D...) anymore as everything is now CIDR and VLSM (http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing)
But as you are using a subnet mask of 255.255.255.192 that equates to a /26 (64 IPS). to computer number of ips per CIDR you can use the following formula num ips (/x) = 2^(32-x) So /26 = 2^(32-26) or 2^6 which is 64.
The rest is basically just binary math.
1 /24 = 2 /25
1 /25 = 2 /26
1 /26 = 2 /27
And so forth.
So when breaking a /24 down into /26 subnets, you will get 4 Subnets of 64 hosts each.
(important to remember that each subnet's size will alway be a power of 2, and they always need to start on bit boundary).
So the first subnet will start at .0 (this isn't always the case, since if you are given a /27 and need to break it down into 4 /29's it is possible that it will start on a different number, but in the case of /24's first subnet is 0)
The IP of the subnet is the network, the last IP of the subnet is the broadcast, the rest of the ips are the useable host addresses.
To compute the useable IPs you would use 2^(32-x)-2. So in your case of /26 ,each subnet will have 62 useable IPS.
So back to first subnet.
195.223.50.0/26
195.223.50.0 is the network (first address)
195.223.50.64 is the broadcast (last address)
195.223.50.1 - 195.223.50.62 are useable hosts
The next subnet's network is 195.223.50.64, and the next one would be 195.223.50.128 and the last one would be 195.223.50.192
what is different when staring with a /16 (standard subnet size for legacy class b networks) is that you start off with 2^16 (65k) IPS to break up into subnets, as opposed to 2^8(256), an you have much greater room to be wasteful.

Related

CIDR vs Classful subnetting

I was studying about Classful addressing with subnetting and Classless addressing but I am not able to clearly understand the difference/advantages between the two of them.
Suppose I have a company wants only 32 public IP addresses I can give them a Class C address with a subnet of 27 bits. Similarly I could give them a CIDR subnet to achieve the same result.
|What is my advantage in using CIDR?
| Why was CIDR required even after subnetting can achieve the same result?
| Shortcomings of subnetting with classful addresses.
Thanks in advance.
You are confusing a couple of concepts. Inter-Domain routing under network classes required that entire address class blocks be assigned to a single entity. There was no way to route inter-domain traffic except by class. You could subnet within a single entity, but you could not divide a classful block between entities.
All CIDR is doing is saying that the classes no longer exist, and you can break up what used to be a classful address block among different entities.
Network classes no longer exist, and they really are studied only for historical purposes. Learn how to subnet using CIDR first (become expert at it), then you can learn about network classes as a history lesson.
Class A starts with first bit 0
Class B starts with first two bits 10
Class C starts with first three bits 110
Class D starts with first four bits 1110
Class E starts with first four bits 1111
My friend, classful addressing is basically dividing the total ipV4 range into five classes :
Class A
Class B
Class C
Class D
Class E
whereas CIDR is based on concept of subnetting.
In your example , your company wants 32 public ip addresses. When we give them a class C address for example : 192.168.2.0 , their company will be reserved for whole ip addresses in range 192.168.2.1 - 192.168.2.254.But they only want 32 ip addresses which means 223 ip addresses will be wasted. This is the constraint of classful addressing . Now if we look at just subnetting , class c ip address has default subnet of 255.255.255.0 so if we divide the range of 192.168.2.0 in 6 subnets each containing 32 available ip addresses your problem is solved. But, if we take this example to higher level we will require CIDR. According to traditional subnetting, we can not combine the addresses from the networks 192.168.2.0 and 192.168.3.0 because the netmask for class C addresses is 255.255.255.0.However, using CIDR notation, we can combine these blocks by referencing this chunk as 192.168.2.0/23. This specifies that there are 23 bits used for the network portion that we are referring to. With this ,the 24th bit can be either 0 or 1 and it will still match, because the network block only cares about the first 23 digits.
CIDR allows us more control over addressing continuous blocks of IP addresses. This is much more useful than the subnetting we talked about originally . Your example only requires subnetting but if we require huge amount of addresses so that we may require to link class C address with class B portion , we will require CIDR.
IP Addresses have stayed the same. What has changed is "How devices can determine Network and Node part from an IP Address. With classful IP Address based processing, the number of bits assigned to network and host parts were fixed. For example when processing ip addresses using classes concept, the system will first determine the class of the IP Address and then use predetermined subnet mask to determine the network portion and host portion.
For class A first octet is network bit which allows 126 networks to be represented.
Due to restrictions on number of hosts and networks imposed by classes, you can define your own subtask mask which represent the network and host part of an IP address regardless which IP Address class you are using. The way that subnet mask is represented in text is called the "CIDR Notation".

taking an ip and getting the subnet mask, & cidr

I have found this website calculator that explains the ip class's (A,B,C,D,E ) and also how to get the subnet mask, he was not very clear about how to configure the number of nodes (formula for figuring out the number of 'host' bits), he says 'Since you know the number of nodes, you need to find 'n'.' to get 2^6 - /26. I don't understand how he knows to use 64 nodes.
subnet calculator
First depict the ip address in binary. Take 61.246.19.18 and convert to binary:
ip address: 00111101.11110110.00010011.00010010
First we determine what class of address it is:
If the first bit is 0 it is a Class A address If the first two bits are 10 it is a Class B address If the first three bits are 110 it is a Class C address If the first four bits are 1110 it is a Class D multicast address If the first four bits are 1111 it is a Class E experimental address
Your example is a Class A address. The default subnet mask for a Class A address is:
subnet mask: 11111111.00000000.00000000.00000000
The formula for figuring out the number of 'host' bits in a subnet mask is
2^n=(number of nodes ) (2^n means '2' to the power of 'n')
Since you know the number of nodes, you need to find 'n'.
Because you want 64 node(s), you want to leave 6 - '0' bits in the subnet mask since 64 = 2 ^ 6.
This will give you the following subnet mask:
subnet mask: 11111111.11111111.11111111.11000000
Which is referred to as /26 or in dotted decimal notation as 255.255.255.192
Most of the topics here i have searched say this cannot be done to find the /cidr range from a given ip address, but this webpage subnet calculator does create the range from a given ip. I understand how to convert ip to binary and also get the class subnet mask, but he did not use these to get his 64 host bits result, I think he skipped how to configure the hosts bits after he converted the class subnet mask.
also alot of the online calculators also require you to manually put the cidr range, to get the ip's range, etc. this seems to be the only calculator example i can find that will create the ip information with only the given ip address.
I need to collect the ip range from just the given ip to block a user from my website from registering, if they have already been banned for chargeback reasons. So I would like to create a php script to compare a new user ip to the banned ip's list ranges. which would determine if they are ban evading by creating new accounts.
Thanks for any help.
From Networking point of view:
/26 means 26 Network bits and 6 hosts bits.
For simplification you can use this formula
Network Bits (NB) + Host Bits (HB) = 32
/26 represents netmask or we can say NB= 26, which means HB = 32-26 = 6
Which means you will have 64 nodes (2^HB => 2^6 = 64) in single subnet.
This simple CIDR Tutorial can be helpful.
You can also identify smallest possible network size from given IPs.
Convert those IP to binary.Then calculate the common bits in IPs, that will be the network bits, based on which you can find subnet mask.
For example
Let's say we have 2 IPs
192.168.24.12 and 192.168.24.76
192.168.24.12 in binary 11000000 10101000 00011000 00001100
192.168.24.76 in binary 11000000 10101000 00011000 01001100
Here first 25 bits are common bits. Which means these IPs can be from /25 subnet.
In this example, the number of nodes is your own input. This is you saying, I have 64 machines and I need to find enough IPs for them all on my given network. Then you use this calculation method to determine the subnet mask and IP allocation.
The article does a poor job explaining this, though.

How many addresses under each subnet

I'm studying IP classes and the topic of subnetting is confusing me.
I'm doing some practice questions and the question I'm stuck on requires me to find number of addresses under each subnet.
What I have so far is, a block 211.17.180.0/24 from which I was able to obtain subnet mask /24 = 255.255.255.0. And that there's 32 subnets. I'm not too sure how to proceed from this point. Normally, I would say there's 254 usable addresses (excluding 211.17.180.0 and 211.17.180.255) but I'm not sure how to deal with 32 subnets.
Ok, I may have figured out how to solve this problem
Since there are 32 subnets, I multiply by 2, getting 64 addresses(multiply because there are 2 unusable address per every subnet)
Then, 256-64=192/32=6, so, there are 6 addresses per every subnet in this block.
I'm not sure if this is the right way to solve this problem, some confirmation would be really appreciated!
From what I understand, the problem mentions that there are 32 subnets inside the /24 block.
Your answer is correct, here's an alternative way to think about it if you think this is confusing:
If there are 32 subnets, it means you'll need 5 bits to encode subnet identification (211.17.180.0/29 through 211.17.180.31/29), which leaves you with 3 usable bits for the host IP on each subnet; since 2 addresses are unusable on each subnet, we get at most 2^3-2 = 6 usable addresses per subnet.

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.
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

Calculating subnet mask [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I have problem calculating a subnet mask.
Suppose xyz college is planning to setup a small private network with network address 192.168.20.0. The number of departments in the college are 7 and the max no. of host in each department is 25. How to calculate subnet mask?
When I tried to google to find a tutorial for calculating such kind of problems, got nothing.
A mask of /27 will give you 5 bits for the host ip addresses and 5 bits will be enough to represent 25 hosts. Each department can go on a different network, eg: Dept A can be 192.168.20.0/27 and Dept B can be 192.168.21.0/27 etc...
I realize this question is 2 years old but thought I'd add to it if others come here with a homework problem similar to this one. Assuming that each network never needs more than 30 hosts, (it states that 25 will be the most) then you could use 5 host bits and 27 subnet identifier bits for each network.
5 bits can represent 30 hosts because:
2^5 = 32
So 32 numbers can be represented with 5 binary bits.
Subtract 2 because the lowest address in each subnet is the network address while the highest address is the broadcast
32-2=30 assignable addresses
4 bits would not have been enough as (2^4)-2=14.
If you go with more bits, you'll have larger gaps between subnets and potentially wasted addresses.
Generally, these are assigned as the lowest available addresses (at least they will be for the sake of your homework).
192.168.20.0 in binary = 11000000.10101000.00010100.00000000
While sashang's answer works, if this is homework, your professor will be looking for you to update the right most subnet identifier (or network identifier) bits first. We know there are 27 bits in the subnet identifier from the "/27" in CIDR notation. They are the first 27 bits in bold below.
11000000.10101000.00010100.00000000
If you increment from the far right and make 7 subnets, here's the subnet addresses you would get. I'll just bold the binary digits that will change and not the rest of the network address to the left.
11000000.10101000.00010100.00000000 = 192.168.20.0/27
11000000.10101000.00010100.00100000 = 192.168.20.32/27
11000000.10101000.00010100.01000000 = 192.168.20.64/27
11000000.10101000.00010100.01100000 = 192.168.20.96/27
11000000.10101000.00010100.10000000 = 192.168.20.128/27
11000000.10101000.00010100.10100000 = 192.168.20.160/27
11000000.10101000.00010100.11000000 = 192.168.20.192/27

Resources