Вы находитесь на странице: 1из 8

# IP Subnetting

IP Subnetting
Introduction
The Internet Protocol (IP) is the de facto standard when it comes to routing network communications in the world today. Although other networking protocols still exist, it is extremely difficult to find a network that is not running IP. A critical skill for any network administrator or security admin that supports a network environment is IP subnetting. This paper discusses why subnetting is important, IP addressing basics, decimal to binary conversion, early subnetting, and variable length subnetting.

## Why Is Subnetting Important?

Before we start dive into subnetting, we need to cover some basics. The first item for discussion is the IP address. An IP address is a 32-bit number typically represented in four sections called octets. These sections are segregated by a dot or period, and you ,hear this format referred to as dotted decimal notation. A sample IP address is 172.16.10.15. This IP address is what identifies a system or resource on a particular IP network. The IP address itself is actually made up of two parts. One part identifies the network that the host belongs to, and the other part identifies the host. To figure out where the network portion stops and the

host part begins you need a subnet mask. A subnet mask is also represented in dotted decimal notation. An example of a subnet mask would be 255.255.255.0. You will see later how the subnet mask is used to identify the network and the host parts of the IP address.

## Decimal and Binary

No discussion on IP subnetting would be complete without mentioning decimal to binary conversion, and vice versa. This is not a math paper, so I will keep this section as brief as possible. Computers speak binary. This means the computer knows only two modes for each bit of data, on or off, or 1 or 0. Alternatively, humans like to see numbers in a base 10 format or 0 through 9 and multiples thereof. In IP subnetting, it is important that we know how to convert IP addresses and subnet masks from their humanfriendly decimal form to the computer-friendly binary form because the locations of the 1s and 0s is extremely important, as you will see later. If we use the sample IP address from before, 172.16.10.15, and represent it in binary format, it would look like this: 10101100.00010000.000001010.00001111. So, how do we get from the decimal form to the binary form, and vice versa? First, lets convert from binary to decimal. If we take the first octet of our sample IP address and map it to the binary numbering system, it looks like this: Binary IP Address 27 1 26 0 25 1 24 0 23 1 22 1 21 0 20 0

If we then add in the decimal equivalents of the binary, it looks like this Binary=Decimal 27=128 IP Address 1 26=64 0 25=32 1 24=16 0 23=8 1 22=4 1 21=2 0 20=1 0

Now all we have to do is add the decimal numbers together where a 1 appears and we will get the decimal equivalent of the binary number. In this case it looks like this: 128 + 32 + 8 + 4 = 172. That wasnt so bad. Now that you know how to convert from binary to decimal, how do you go from decimal to binary? I thought you would never ask. To convert from decimal to binary, you use division and remainders. Lets take our 172 example from previously. The formula for conversion is as follows. 1. First divide the number by 2. The remainder will be either 0 or 1. 2. Write down the remainder. 3. Divide the remaining number without the remainder by 2. Again, the remainder will be either 1 or 0. 4. Write down the remainder to the left of the previous remainder. 5. Repeat this until you end up with 0. For 172, the formula would look like this: 172 2 = 86 remainder 0 86 2 = 43 remainder 0 43 2 = 21 remainder 1

21 2 = 10 remainder 1 10 2 = 5 remainder 0 5 2 = 2 remainder 1 2 2 = 1 remainder 0 1 2 = 0 remainder 1 So our binary number for 172 = 10101100. Remember that each section of an IP address is 8 bits long. In the previous example, the conversion worked out to 8 bits exactly, so that was easy. If we used a smaller number such as 15, we would have reached 0 before we had 8 bits. If this occurs, fill in the remaining bits with 0s. For example: 15 2 = 7 remainder 1 7 2 = 3 remainder 1 3 2 = 1 remainder 1 1 2 = 0 remainder 1 Because we got to 0 in only four steps, the remaining bits are 0--so the binary of 15 is 00001111. Okay, enough math; lets talk about IP subnetting.

Early Subnetting
In the beginning, IP addresses were traditionally broken up into five classes lettered A through E. Classes A, B, and C were used for your average IP networks; Class D was used for multicast networking; and Class E was for experimental usage. The determination of which class a particular network fell in was determined by the first octet of the IP address, specifically by the first few bits of the first octet. This is represented in the following table. First Bits Class A Class B Class C Class D Class E 0 10 110 1110 11110 1st Octet 1-126 128-191 192-223 224-239 240-254 Number of Networks 126 16,384 2,097,152 n/a n/a Hosts per Network 16,777,214 65,534 254 n/a n/a

Because Classes D and E are special classes, we will focus our discussion on Classes A, B, and C. Each of these classes has a default subnet mask and a private address range. The private address ranges are utilized on internal networks, and addresses in these ranges cannot be routed in the public network of the Internet. These defaults and private ranges are shown here: Default Subnet Mask Class A Class B Class C 255.0.0.0 255.255.0.0 255.255.255.0 Private Address Range 10.0.0.0 10.255.255.255 172.16.0.0 172.31.255.255 192.168.0.0-192.168.255.255

As we mentioned before, the subnet mask is used to identify which portion of the IP address is the network and which portion of the IP address is the host. To visually see how this works, we need to represent our IP address and subnet mask in binary format. See, I told you the binary stuff would come in handy. Lets take our initial sample IP address of 172.16.10.15. As you can see from the previous table, this is a Class B address with a default subnet mask of 255.255.0.0. Lets represent that in binary. 172.16.10.15 255.255.0.0 10101100 11111111 00010000 11111111 00001010 00000000 00001111 00000000

VLSM

## 172.16.1.255 172.16.2.255 .. 172.16.253.255 172.16.254.255

That is basic subnetting; now lets get a little more creative. Lets say we have a number of small field offices that have no more than 20 hosts. If we issue a Class C network to each office, we are going to waste approximately 230 addresses in each network. If we use VLSM, however, we can get a more efficient use of our subnets. The first question we need to ask is how many host bits do we need to leave in the subnet mask to give us more than 20 hosts per network. This is very simple to determine. The formula to determine the number of hosts per network is 2 raised to the number of host bits in the subnet mask 2. The reason we subtract 2 is because the host ID cannot be all 1s or 0s. So if we look at a class C subnet mask in binary form (11111111.11111111.11111111.00000000), we can see that there are 8 host bits. 28-2 = 254 host addresses. In the following table you can see the number of hosts per network if we were to change the host bits in a Class C subnet mask. Host Bits Changed 1 2 3 4 5 6 Binary Notation of Last Octet 10000000 11000000 11100000 11110000 11111000 11111100 Dotted Decimal Notation 255.255.255.128 255.255.255.192 255.255.255.224 255.255.255.240 255.255.255.248 255.255.255.252 /# Format /25 /26 /27 /28 /29 /30 Number of Hosts 27-2 = 126 26-2 = 62 25-2 = 30 24-2 = 14 23-2 = 6 22-2 = 2

Because we need 20 addresses, we can see from the table that we will need to change 3 host bits. It is important to remember that when you change the host bits, you always start from the far left and work your way to the right. We have decided that we are going to use the 192.168.10.0 network as our starting point for our subnetting. We know that our subnet mask is going to be 255.255.255.224. From this point, there are three final items that we need to determine. 1. What are the networks we have created with our new subnet mask? 2. What are the host ranges in those networks? 3. What is the broadcast address for each network? The first step is to determine what our networks will be. To do this, we need to look at the subnet mask in binary notation where we changed host bits to network bits. This is shown below.

Binary=Decimal 27=128

26=64

25=32

24=16

23=8

22=4

21=2

20=1