33

It appears to be common practice to not use the first address in a subnet, that is the IP 192.168.0.0/24, or a more exotic example would be 172.20.20.64/29.

The ipcalc tool I frequently use follows the same practice:

$ ipcalc -n -b 172.20.20.64/29
Address:   172.20.20.64         
Netmask:   255.255.255.248 = 29 
Wildcard:  0.0.0.7              
=>
Network:   172.20.20.64/29      
HostMin:   172.20.20.65         
HostMax:   172.20.20.70         
Broadcast: 172.20.20.71         
Hosts/Net: 6                     Class B, Private Internet

But why is that HostMin is not simply 64 in this case? The 64 address is a valid address, right? And whatever the answer, does the same apply to IPv6?

Perhaps slightly related: it also appears possible to use a TCP port 0 and an UDP port 0. Are these valid or used anywhere?

Shtééf
  • 1,225
  • 2
  • 12
  • 19

8 Answers8

39

I know this is an old thread but I was researching this myself and I didn't stop at "host zero isn't used because it is the network number" because I couldn't see why that mattered. Even if it is the network number it shouldn't stop it being used as a valid address as the mechanism to determine network number (ANDing the netmask) will still work with it to determine the network number.

Not using the all ones host address because it coincides with the broadcast address I was comfortable with, as it is a valid destination address already so when used it would be impossible to distinguish between those.

The more fully explained reason we can't use host zero is that it is also a broadcast address - although RFC1812 section 4.2.3.1 states that a router receiving packets addressed to it "SHOULD silently discard" them (their emphasis - not mine). However the same paragraph does allow those packets to be treated as a broadcast.

Here is the full sub-section

   (2) SHOULD silently discard on receipt (i.e., do not even deliver to
    applications in the router) any packet addressed to 0.0.0.0 or {
    <Network-prefix>, 0 }.  If these packets are not silently
    discarded, they MUST be treated as IP broadcasts (see Section
    [5.3.5]).  There MAY be a configuration option to allow receipt
    of these packets.  This option SHOULD default to discarding
    them.
Jimbugs
  • 491
  • 1
  • 4
  • 2
  • 15
    +1 for not stopping on "it is the network number". As a thought, this RFC standard clearly wastes IP addresses, because there seems to be no technical reason for discarding such packets, nor there's a reason to have two broadcast addresses per subnet. Think how many host addresses could have been used in this running-out-of-IPv4-addresses world! – Iravanchi Mar 11 '13 at 08:16
  • +1 Thank you! Someone gets it at least. – Gremio Oct 18 '13 at 21:08
  • 2
    +1 This notion of mask.0 being off bounds probably stems from early convention. Some time ago a Linux based server once had an IP address x.x.x.0/24, and it worked OK, except some windows applications refused to connect to it, citing the IP address being invalid. There were no IP routers involved in the equation, only switches. – Spacen Jasset Mar 07 '16 at 13:44
22

Because the first address in a subnet refers to the subnet itself and is used for routing purposes.

Chopper3
  • 100,240
  • 9
  • 106
  • 238
  • 3
    +1 for mentioning the routing table significance of the network address. One liners are important too... =) – Wesley Apr 23 '10 at 15:52
  • 2
    I am going to apologize. I have been having a long running debate about the use of network 0 and network all 1's when subnetting. Yesterday, on multiple occasions, I read network when the word was host. So I am sorry. I considered just deleting my other posts, but that would not have been honest. – dbasnett Oct 30 '10 at 11:06
  • @dbasnett, well thank you very much indeed, you didn't have to do that. Because this site tends to attract the more novice users I'd say that very often you'll see answers on here that have some minor inaccuracies simply because we try to write our answers for a very general audience so that people searching via google etc. are drawn to the site and gain some benefit. There are big grey areas in this question and some of the answers which you rightfully picked up on but this isn't a site for cisco experts to dig deep into detail, but more to answer in the spirit of the questions. Thank you. – Chopper3 Oct 30 '10 at 11:22
  • 4
    The first host address in a subnet is *not* used for routing purposes--I keep seeing this misconception. An IP address plus a subnet mask is used for routing and performing the comparisons necessary. The ability to facilitate routing is not affected by using the first address in the scope as a host address. The network address is shown in routing tables for clarity and ease of calculations, not because it's being assigned or used up in the routing process. A route of 192.168.32.5/16->192.168.0.1 is just as valid as 192.168.0.0/16->192.168.0.1--which would you rather see? – Gremio Oct 18 '13 at 21:00
15

As Wesley, Chopper3, and Willy pointed out modern convention uses the first address (all zeroes host number) for the subnet and the last address (all ones host number) as the broadcast address.

For historical reasons many OSes treat the first address as a broadcast. For example, pinging x.x.x.0 from OS X, Linux, and Solaris on my local (/24) network gets responses. Windows doesn't let you ping the first address by default but you might be able to enable it using the SetIPUseZeroBroadcast WMI method. I wonder if you could get away with using .0 as a host address on an all-Windows network.

Gerald Combs
  • 6,331
  • 23
  • 35
8

Early in the internet days, x.x.x.0 was used as the broadcast address for a network. That was later changed to x.x.x.255. I remember that there were options on SunOS to configure the broadcast either as .0 or .255 during that period. So I guess for safety, .0 and .255 have been always a reserved numbers.

mdpc
  • 11,698
  • 28
  • 51
  • 65
6

The first number in a subnet is the network's address itself. so 192.168.0.0/24 is the number that is used to refer to that subnet. Of course, the last address is the broadcast address where broadcasts are sent to and then pushed down to all clients on that subnet. In IP networking, you always remove 2 from the broadcast address to find the total amount of addressable IP addresses. 192.168.0.0/24 has a broadcast of 192.168.0.255 and thus 253 addressable addresses. 192.168.0.0/26 has a broadcast of 192.168.0.64 and thus 62 addressable addresses.

(Chop and Willy beat me to it -- but I'm grumpy and don't feel like deleting my post. =) )

Wesley
  • 32,320
  • 9
  • 80
  • 116
  • +1 for being grumpy ... now where is my coffee – Zypher Apr 23 '10 at 15:22
  • +1 for not being a 1 line answer – Jim B Apr 23 '10 at 15:25
  • +1 for the same reason, it's a better answer than mine :) – Chopper3 Apr 23 '10 at 15:39
  • 3
    Many OSes treat the first address as a broadcast. For example, pinging x.x.x.0 from OS X, Linux, and Solaris on my local (/24) network gets responses. Windows doesn't let you ping the first address by default but you can apparently enable it using the SetIPUseZeroBroadcast WMI method. I wonder if you could get away with using .0 as a host address on an all-Windows network. – Gerald Combs Apr 23 '10 at 16:08
  • 1
    @Gerald Combs: Thanks for pointing out the exact limitations of the 0 address. This is actually the answer I'm looking for! Perhaps you can convert/repost it so I can accept? – Shtééf Apr 23 '10 at 17:42
  • @Shtééf It's now an answer. – Gerald Combs Apr 23 '10 at 17:55
  • A small correction: broadcast address of 192.168.0.0/26 is 192.168.0.63 - the rule is that the host part of the address must be all zeros. – L.R. Apr 23 '10 at 18:04
  • 2
    A /24 has *254* host-assignable addresses (from .1 to .254) while a /26 has 62 host-assignable addresses (correct, but because you used .64 as a broadcast address, which is wrong. Your "subtract 2" rule is wrong, you don't take it from the broadcast address, but from the number of valid addresses in that subnet, which is 2^(32-n) where n is the prefix length (/n). For example, 192.168.0.252/30 doesn't have 253 usable addresses (that is absurd), but do have 2^(32-30) - 2 = 2^2 - 2 = 4 - 2 = 2 usable addresses. – Juliano Oct 29 '10 at 14:42
  • 1
    Why stop at /24? A /23 subnet has 512 total addresses, of which n.255 and (n+1).0 fall smack dab in the middle of the subnet, are neither the network or broadcast addresses, and *should* be allocable. However, since the RFC1812 section 4.3.2.1 apparently does not make this distinction, one must assume that .0 will be discarded regardless of its position in the network. – Jonathan J Mar 13 '15 at 20:57
4

Host number 0 in every subnet is reserved primarily because it used to be a broadcast address.

The RFC says, paraphrased, should discard, but alternatively, use as broadcast, but also usable as a host number via some non-default option.

Now, octet 0 as in x.y.z.0 may very well be a perfectly valid non-zero CIDR host number, but in the past it would very occasionally have problems at isolated sites due to implementation bugs (possibly leftover class-full code) in the site's HW or SW.

Today, octet 0 works well enough to be assigned by ISPs and cloud platforms, though no doubt some services deliberately don't hand it out based on past experience.

Interestingly enough, all it would take to support host 0 at any specific site is support by the exact devices present on the local subnet ... once the packet is aggregated upstream it wouldn't even be possible to know that it actually had (CIDR) host number 0 in use. The WAN would not care at all.

Finally, if the local subnet's hosts use the all-1's host number for broadcasts and don't special-case the all-0's host number, you could leave the router in default and have a local-only "hidden" station. That might be useful for protecting embedded systems, like hack-prone cheap consumer routers...

DigitalRoss
  • 848
  • 1
  • 5
  • 15
3

x.x.x.0 (or first address on a subnet) is the network address and is used to identify which traffic is on the same subnet, and which needs to be routed to a different network.

  • 1
    If I take 192.168.0/23 (Which start at 192.168.0.0, and ends at 192.168.1.255) then 192.168.1.0 is a valid IP. Thus your "x.x.x.0" is not always correct. – Hennes Nov 22 '12 at 19:25
3

There are two reserved IP addresses per CIDR block. One is "the" network number and it will be even(bit 0) off. The other is the directed braodcast (subnet broadcast) and it will have the host portion of the network set to all ones (odd number). Here is an example from my subnet calculator:

Network           Net Broadcast     CIDR Mask              UsableHosts 
192.168.254.0     192.168.254.31    27   255.255.255.224   30          AVL  isPrivate, isClassC
192.168.254.32    192.168.254.47    28   255.255.255.240   14          AVL  isPrivate, isClassC
192.168.254.48    192.168.254.55    29   255.255.255.248   6           AVL  isPrivate, isClassC
192.168.254.56    192.168.254.59    30   255.255.255.252   2           REQ 2  isPrivate, isClassC
192.168.254.60    192.168.254.63    30   255.255.255.252   2           REQ 2  isPrivate, isClassC
dbasnett
  • 683
  • 5
  • 11