1

Let's have the following address of the network: 192.168.176.0/23. What are the first and last IP addresses of this network?

Following this answer https://serverfault.com/a/327782/288201 I assume that:

/23 means 23 bits for the subnet. At 8 bits per byte we get 16 bits for the first two bytes, and then seven (7) for the third => 1111 1111. 1111 1111. 1111 1110. 0000 0000, right?

It means our last two bytes will be of the form (nnnn nnnH. HHHH HHHH), where n is a subnet bit and H a host bit.

Thus the network address is (nnnn nnn|0 0000 0000) -> .0, the broadcast is (nnnn nnn|1 1111 1111) -> 2^9 is broadcast? Impossible. Here I miss something, something simple. So what would be the first and last IP? This is what I don't get following the answer mentioned in the link above (by b0fh).

First 192.168.176.1, last 192.168.177.254?

zus
  • 23
  • 1
  • 1
  • 8
  • 1
    You've answered your own question. It's correct. Why do you think it's impossible? – Andrew Schulman May 10 '15 at 10:55
  • Maybe I just interpreted it incorrectly. 2^9 is 512 and it cannot be value of broadcast of couse (max. only 255), right? But it is number of hosts (minus 2 reserved for network address and broadcast). But how I get the first and the last IP? Especially the last one is the one I'm not sure about. Do I really add +1 to the 176 and the rest is 255 - 1? – zus May 10 '15 at 11:00
  • @zus I think what you need to realize is that with [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) (what we have all been using since the mid nineties), the octet boundaries are of little importance. – Håkan Lindqvist May 10 '15 at 11:22

2 Answers2

2

I'll try to clarify what I interpret as your source of confusion:

An IPv4 address is a single 32 bit integer but it's not normally formatted that way when we write out an address.

As I'm sure you are aware, the norm is to write the address as [first eight bits in decimal].[next eight bits in decimal].[next eight bits in decimal].[last eight bits in decimal] but it's important to realize that it's really just a different way of formatting that single, potentially very big, number.

When you specify a CIDR netmask (/n) that says how many bits out of the 32 bit address form the network identifier, the remaining bits forming the host identifier.


In your example, 192.168.176.0/23, the first 23 bits are the network prefix, leaving 9 bits for the host identifier, which means that the host identifier straddles the last octet boundary. The host identifier will affect the last two segments of the a.b.c.d-formatted address.

To illustrate this, I'll include sipcalc output showing both the addresses as raw bits (really more relevant to understanding the math) as well as a.b.c.d-formatted addresses.

$ sipcalc -b 192.168.176.0/23                                                                                             
-[ipv4 : 192.168.176.0/23] - 0

[CIDR bitmaps]
Host address            - 11000000.10101000.10110000.00000000
Network address         - 11000000.10101000.10110000.00000000
Network mask            - 11111111.11111111.11111110.00000000
Broadcast address       - 11000000.10101000.10110001.11111111
Cisco wildcard          - 00000000.00000000.00000001.11111111
Network range           - 11000000.10101000.10110000.00000000 -
                          11000000.10101000.10110001.11111111
Usable range            - 11000000.10101000.10110000.00000001 -
                          11000000.10101000.10110001.11111110

-
$


$ sipcalc  192.168.176.0/23                                                                                               
-[ipv4 : 192.168.176.0/23] - 0

[CIDR]
Host address            - 192.168.176.0
Host address (decimal)  - 3232280576
Host address (hex)      - C0A8B000
Network address         - 192.168.176.0
Network mask            - 255.255.254.0
Network mask (bits)     - 23
Network mask (hex)      - FFFFFE00
Broadcast address       - 192.168.177.255
Cisco wildcard          - 0.0.1.255
Addresses in network    - 512
Network range           - 192.168.176.0 - 192.168.177.255
Usable range            - 192.168.176.1 - 192.168.177.254

-
$ 
Håkan Lindqvist
  • 33,741
  • 5
  • 65
  • 90
0

What's confusing you is that you are trying to convert the host part into a decimal value and sum it up to the network address while the host part is split in two octects.

Your network is :

11000000.10101000.10110000.00000000

Your netmask is :

11111111.11111111.11111110.00000000

Your wildcard mask (the part that will change) :

00000000.00000000.00000001.11111111

Typically, when you say 2^9 = 512 is broadcast, you are simply forgetting that one bit of the host part is in the last bit of the third octect. So as it changes you will get either this :

11000000.10101000.10110000.<something>

Or this :

11000000.10101000.10110001.<something>

So here your "512" decimal form is in fact 0.0.1.255 (should always be dotted decimal form so you don't make this mistake). The non-network part will go from 192.168.176.0 to 192.168.176.0 + 0.0.1.255. The last address being the broadcast address you find out that this is 192.168.177.255.

You can also get it by adding the wildcard mask to your network address :

  11000000.10101000.10110000.00000000

+ 00000000.00000000.00000001.11111111

= 11000000.10101000.10110001.11111111

Which is 192.168.177.255.

Xavier Lucas
  • 12,815
  • 2
  • 44
  • 50