How do I calculate the total number of addresses in a subnet?

How do you calculate network address?

I have been using the code from this post to calculate a network address, but when I run it I get a result of xxx.xxx which seems to be the default address assigned to my machine.

Here is the code I am using: public static string GetIPAddress(). return sb.ToString();
It's just what you're doing - appending to the string builder. You're not returning anything, so whatever value you get in your code is being used as the return value. If you need to get the IP address, don't return it - use a different variable name and then do something with that variable (ie. Console.WriteLine(ip)).

In fact, that code won't even compile unless you add a using System.Net; line at the top.

How do I calculate the total number of addresses in a subnet?

You can use the /28 notation and the subnet mask. The subnet mask is 255.128, giving an address range of 256-511 in decimal. That is, an IPv4 address is a number with 28 bits and the last bit is zero.

A /28 network contains all IP addresses that have the last bit set to 0. To calculate the total number of addresses in a subnet, just count how many /28 subnets there are. If the last bit is not zero, you are in one of these subnets. If it is zero, you are in one of the other subnets.

If your subnet mask is 255. You just count the addresses. Each octet of an IP address has either zero or two of the possible 8 bits set. So the first octet has 28 of the possibilities and the last octet has one of the possibilities.

EDIT: What I said above is correct for IPv4 addresses. IPv6 addresses are a bit more complicated, but essentially the same. Each IP address has a value which is a multiple of 8. The highest order bit indicates whether or not the address is a "special" address, such as loopback. The other bits specify the other 7 address values.

What is the network address for an IP address?

I have an IP address for a computer that I want to ping and it has a different network address than what is on the router. What is the network address on the router for this computer? It is the router's IP address, but what you are asking for is its subnet mask. The mask is the way to partition the network into different parts. Each part will be represented by a unique number, which is a subset of all the possible numbers in the range of 1 through 255.

An example: (255.0) means 255 = any value (so 0 through 255), and .0 = any number (any value).

In this case, .0 would mean 0 through 127, 255 would mean 128 through 255.

This would make the network 255.0 Note that subnetting works in a similar way. For example, 0.0 is the network, .0 is the first range of bits, and .0 is the last range of bits.

Related Answers

Can you unlock an iPhone using the calculator?

I had the passcode on my iPhone a...

Is there a free online graphing calculator?

That's a question I've asked myself, because there are plenty of g...

What calculator is allowed on the SAT?

What about the TI-81? I never thought of it. I was just wonder...