CIDR notation. Breaking out of Classful subnetting

You may have already noticed that IP address classes are pretty limited in terms of the size of networks you can allocate. When TCP/IP was created, it was simple for humans to understand the address classes because the broke cleanly on octet boundries (right at the dots in an IP address). Furthermore, no one was particularly concerned about the potential inefficiency and wastage of IPs when the supply of IPs seemed inexhaustable.

They're not inexhaustible, of course, and something had to be done. The breaking of IP space on 8-bit boundaries was a convenience mechanism but it's not necessary to break your subnet and host parts on 8-bit boundaries. CIDR, Classless Internet Domain Routing, was invented to solve the related problems of IP address shortage.[1]

A traditional Class C network division looks like this using 24 bits for the network part and the remaining 8 bits to represent the hosts:

   255     255      255       0
11111111.11111111.11111111.00000000
\-------network----------/ \-host-/
    

It's very easy to see how the network breaks on the third octet.

But it's not necessary to do that. Here, we subdivide our traditional class C expanding the netmask by one bit beyond the octet boundary. So we're using 25 bits for network part now.

  255      255      255     128  
11111111.11111111.11111111.10000000
\-------network----------/ \-host-/
    

So this changes our netmasks and we get masks that look like 255.255.255.128 for example. Instead of using 24 (8*3) bits for our network part, we're using 25 bits -- hence the change in the last digit of the mask. This network essentially divides a class C network of 256 total addresses into two subnetworks of 128 addresses each. Of course you then lose 4 addresses, 2 in each subnet, for the network and broadcast addresses. your subnets then look like this:
   192.168.0.0 - 192.168.0.127
      192.168.0.0 is network address, 192.168.0.127 is broadcast address
   192.168.0.128 - 192.168.0.255
      192.168.0.128 is network address, 192.168.0.255 is broadcast address

CIDR also gives us a new form of notation referred to alternately as "cidr notation","prefix notation", or "slash notation". Using this method, we note the network prefix part of an address by adding a "/" followed by the number of bits used for the network part. Thus a Class C address can be described in prefix notation as 192.168.0.1/24 . This is a convenient shorthand for describing IPs within their network contexts. Applications that accept this notation can easily calculate the network information from the prefix address. In our sample above we have 192.168.0.0/25 and 192.168.0.128/25 for our networks. You will sometimes here network admins referring to networks as a "slash 24" instead of Class C and the like.

We don't have to divide up the common /24 (aka Class C). We can divide to fit our needs. For example a /23 gives us a network of 512 addresses. It can be described as a further subnet of the traditional Class B (/16) network or as a supernet combining 2 traditional Class C sized networks.[2]

CIDR can be a bit hard on humans to calculate. With traditional classful networks, just looking at the .'s helped to show you where the networks ended and the hosts began. There are numerous programs for Linux and other OS's that do subnet calculation for you. There are two commandline tools for *nix, cidr and ipsc. There are also graphical tools such as gipsc which is a GNOME IP subnet calculator. I even have an IP calculator on my palm pilot.

Most linux literature I have read on TCP/IP avoids classless networking, but it has actually been in common use on the internet for quite some time. You may have already been familiar with traditional Classful networks and been curious about those "strange" looking subnet masks. Since it's become so common in the real world, we figured you ought to know about it.

You should also know about it because it's the source of some common mistakes. Network providers are now allocation smaller subnets out of what was traditionally considered class A space. For example, most of the Cable providers have allocations from 24.0.0.0/8 for their modem pools. This creates a problem sometimes when you don't specify a mask with certain applications; may applications will assume the traditional classful subnet mask if none is given. If you were to set up your network interface using ifconfig (1)[3]on a Linux box like: ifconfig eth0 24.1.2.3 because your cable provider gave you that as your static address, ifconfig would automatically assume a mask of 255.0.0.0. This would likely cause you to not be able to route or at least make millions of hosts on the Internet in the 24.0.0.0/8 network invisible to your machine. Thus it's critical to specify the appropriate netmask and not allow software to apply default Classes.

Just to give you some more examples to pore over, below are examples of subnets and how they break ip address ranges into sections.

Table 1-5. Subnetting examples table

Number of subnets required for a Class A Network Number of hosts Number of bits used in the subnet mask Subnet Mask
241943022 255.192.0.0
620971503 255.224.0.0
1410485744 255.240.0.0
305242865 255.248.0.0
622621426 255.252.0.0
1261310707 255.254.0.0
254655348 255.255.0.0
Number of subnets required for a Class B Network Number of hosts Number of bits used in the subnet mask Subnet Mask
2163822 255.255.192.0
681903 255.255.224.0
1440944 255.255.240.0
3020465 255.255.248.0
6210226 255.255.252.0
1265107 255.255.254.0
2542548 255.255.255.0

So as you can see, using a non-standard subnet mask, you can break the ip addresses into subnets to fit more specific needs.

We could spend many many pages talking about subnet masking, and spend many many hours delving into the deep dark recesses of this subject. But, this is intended as a beginners course to help you understand the basics of subnets, not turn you into a certified network engineer. Get yourself a good book on tcp/ip, and believe it or not, there are a couple of the Microsoft course books for mcse tcp/ip test that are pretty good. The TCP/IP for dummies book, both the msce dummies book and the standard one are both very good for someone to start with.

Notes

[1]

It was also created to alleviate the growing amount of individual routes by creating aggregate 'supernets' but we won't be discussing that topic here.

[2]

That also means that the private space designated as 192.168.0.0/16 in the previous section need not be broken into 256 /24 (Class C) blocks. It can be used simply as one whole network (supernet) of /16 size or split into subnets of varying sizes according to the user's needs.

[3]

see the ifconfig man page and it will tell you this