Networking

TechRepublic Tutorial: Subnetting a TCP/IP network

Learn the basics of IP addressing, reasons to subnet, and the logic behind slicing up an IP network.

Subnetting involves dividing an IP address range into two or more separate ranges, called subnets. Although subnetting can be done for a variety of reasons, from departmental to geographic to political, it is usually done to simplify administration in some way. Breaking networks into smaller, easily defined subnets allows the administrator to better address data flow and security and creates a logical map that can facilitate troubleshooting in the event of a problem. Subnetting involves the use of an IP address and subnet mask to determine whether a destination network is local or remote. I'm going to explain the basics of IP addressing, reasons to subnet, and the logic behind slicing up an IP network.

IP addressing
IP addresses are perhaps the most fundamental components of modern networking. They are the identifiers that computers use to talk to each other on a TCP/IP-based network (including the Internet, most corporate networks, and many home networks).

An IP address is a 32-bit number represented in a dotted decimal format. This address is further divided into four sections, with each section representing eight bits or an "octet." So this 32-bit, four-octet number is in many ways similar to a telephone number. Like a telephone number, it must be unique.

Although there are roughly four billion or so available IP addresses, we still need to be picky with how many are given out. With the dawn of the Internet and our increasingly IP-enabled world, every address counts. In the United States, the American Registry for Internet Numbers (ARIN) handles the management of public IP addresses. Typically, addresses are handed out by ISPs and fall under their management. An ISP will have multiple pools of addresses (and subnets) to assign.

Also, as defined in RFC 1918, private networks are available. These are for internal use and are not routed through the Internet. Private addresses look like this:
 
10.0.0.0 – 10.255.255.255
172.16.0.0 – 172.31.255.255
192.168.0.0 – 192.168.255.255

In IP version 4 (IPv4), the standard that currently dominates the networks of the world, IP addresses fall into one of five classes: A, B, C, D, or E. Classes D and E are for multicast and experimental uses, respectively, and are less common. A, B, and C networks are defined in this table:

First Octet  Class      Subnet mask 
1-127 Class A 255.0.0.0
128-191 Class B 255.255.0.0
192-223 Class C 255.255.255.0

This use of classes represents the original method of dividing networks, but it is somewhat dated. There just isn’t enough middle ground between B and C. While a standard class C network contains 254 addresses (too few addresses for a moderate-size company), a class B network has 65,534 (far too many for the average network). This is where subnetting comes into play.

Reasons for subnetting
Before the advent of subnetting, networks were divided solely on the basis of class. This was a good place to start, but it soon became obvious that greater flexibility would be needed. For one thing, we’re quickly running out of usable addresses in IPv4 as the Internet continues to expand. Since IPv6 (the next version of the standard) is still around the corner, subnetting remains a practical way to get more use of the IPv4 system.

Subnetting is also used commonly in a number of other circumstances. For instance, in a mixed media environment, you usually see a separation between hosts using Ethernet and hosts running on Token Ring. Performance can also be a reason for subdividing one network into two or more. On Ethernet networks, all hosts in the same broadcast domain will need to share the wire. This means a lot of communication is going on, and collisions will rise, increasing latency. If you had an entire class C in one subnet, it would be a good idea to cut it into some smaller chunks to make better use of available bandwidth and to enhance performance.

But subnetting is not just a way to extend class-based IP addresses or solve performance issues; it can also be used for a number of administrative purposes. Creating separate ranges of IPs based on a logical design allows an administrator to more easily view and manage the network. Traffic flows can be better studied and handled, security between subnets is increased, and overall organization is improved.

Learning how subnetting works
Okay, now let’s see how subnetting is actually done. The key player in subnetting is the subnet mask. A subnet mask, also 32 bits, divides the IP address into network and host sections. This allows the sending computer to determine whether routing will be required when communicating to another system. If the computer determines that it is a local address, the packet is sent via Ethernet (or another Layer 2 mechanism). If the address is not local, the packet is forwarded to the default gateway for routing.

First, the IP address is converted to binary, and the network address of the system is determined. The source IP and subnet mask are compared to get this. This is done so we can eventually compare it to the destination network. If they match, the destination is local; otherwise, the packet is forwarded along to a router.

It helps to have an understanding of the binary math involved in the above computations. Let's start by looking at how to convert an IP address to binary. The table below shows that binary math is made up of bits and values, which correspond to the numbers in an IP address:

Bit 1 2 3 4 5 6 7 8
Value 128 64 32 16 8 4 2 1

So given an address such as 192.168.0.1 and a mask of 255.255.255.0, what does that mean? Let's break down the four octets of 192.168.0.1.

To get the 192 in the first octet we need a 128 and a 64 (added together they equal 192), which would look like this:

Bit 1 1 0 0 0 0 0 0
Value 128 64 32 16 8 4 2 1

To get 168 for the second octet requires a 128, a 32, and an 8:

Bit 1 0 1 0 1 0 0 0
Value 128 64 32 16 8 4 2 1

The next two are easy with all zeroes for the third octet and a single 1 for the fourth octet:

Bit 0 0 0 0 0 0 0 0
Value 128 64 32 16 8 4 2 1

 

Bit 0 0 0 0 0 0 0 1
Value 128 64 32 16 8 4 2 1

When put together, the binary representation of 192.168.0.1 is:
 
11000000.10101000.00000000.00000001

Next, we’ll break down the subnet mask, which in our example is 255.255.255.0. In binary, that would look like this:
 
11111111.11111111.11111111.00000000

This was pretty easy. As you can see above, decimal 255 is the same as having all 1s. Therefore, a mask of 255.255.255.0 tells us that the first three octets are used for the network portion of the address and the last octet is used for the host portion. Reading from left to right, wherever the 1s stop in the subnet mask is where the network portion of the address stops. The 0s represent the host portion of the address. Thus, if you compare the IP address to the subnet mask and you bring down the 0s in the subnet mask to "erase" any of the 1s in corresponding slots in the IP address, you will arrive at the network address. Here's a look at how it works:

11111111.11111111.11111111.00000000  255.255.255.0 [Subnet mask]
11000000.10101000.00000000.00000001  192.168.0.1     [IP address]
11000000.10101000.00000000.00000000  192.168.0.0      [network address]

Subnetting means planning
Before actually subnetting a network, it’s good to do some planning. How many host addresses will be needed? How much room will be needed for expansion? It’s easier to make room when first subnetting than it is to go back later and resegment a large network.

Also remember that in every IP subnet, there will be a network address and broadcast address. In our example, the network address would be 192.168.0.0 and the broadcast would be 192.168.0.255. You can't use these two addresses for hosts. That leaves us with 192.168.0.1-192.168.0.254 to use with hosts. No matter how you subnet your network, you must always remember to avoid using the network address (the first address) or the broadcast (the last address) for any hosts.

Valuable knowledge
Of course, there's a lot more to subnetting, but this should help you to understand basics. I recommend downloading a subnet calculator and playing with some example networks. The more you work with IP addressing and subnetting, the easier it becomes.

Knowledge of subnetting can be extremely helpful, even if you aren’t breaking up networks all the time. Not only will it help you manage whatever networks may be under your control, but it’s also good to have an understanding of what’s going on in the background. Being able to subnet helps you understand how computers make decisions on whether to route a packet. Subnetting also allows you to make better use of available IP addresses, makes dividing networks easy, and allows you separate subnets logically.
0 comments