Monday, July 13, 2009

TCP/IP Addressing

This article goes in depth on TCP/IP addressing with the use of subnet masks. Before you continue, be sure you have a good grip on counting with binary, we have provided a quick binary primer if you need a refresher.

MAC Address - Review

A MAC address (Media Access Control) is a unique address given to each network host (this includes computers, PLCs - programmable logic controllers, routers, switches, and wireless devices. This does not include hubs). In other words anything that makes a decision about the flow of network traffic or talks on the network itself. For more information, read our article on MAC addresses.

Clue: Think of a MAC address like a person's diver's license number, it is just a number that is unique from anyone else's. Now think of an IP address like a person's mailing address. The mailing address group people into zones by using the zip code, city, state, and street identifiers.

Enter the IP address

The IP address provides the grouping capability that MAC addresses do not. An IP address not only provides a grouping hierarchy but can be freely assigned and moved from one host to another. This grouping capability allows a host to differentiate local computers and distant ones so that communication to a host that is local could be direct and communication to a distant host could be efficiently routed.

Big Picture

Ok that is a quick discussion of why you need TCP/IP and its routing capabilities. Here is the real meat: TCP/IP addressing is actually in binary; even though everyone is used to seeing TCP/IP addresses using four numbers ranging from 0 to 255 the reality is, the address is binary but for us humans it is displayed in decimal format. If you convert an IP address from decimal numbers to binary, you will get four 8-bit binary numbers for a total of 32 bits.

I highly recommend that you brush up on binary before going any further. Make sure you can convert between decimal and binary numbers. Once again, refer to our tutorial on binary.

The Internet before subnet masks

Early on, to get IP address space on the Internet you were assigned a class A, B, or C block of addresses. A class A block was an address similar to: 124.xxx.xxx.xxx Where the Xs are address numbers between 0 and 255.

Since each segment of an IP address is 8 bits long, and there are 4 segments, it takes 32 bits to make up a whole IP address. From the example above, we can calculate the total number of hosts available on a class A address block. Since the last 3 segments are free to assign to the hosts in the address block, the total number is 2 to the power of 24 (32 bits in total address length, minus 8 bits used up for the network block address that was assigned; 124.XXX.XXX.XXX it is the 124 in this case). That is almost 16.8 million IP addresses! Class B address blocks were: 212.156.XXX.XXX (2 to the 16th power) 65.5 thousand addresses and a Class C network would give you 256 addresses. Below is a table of how each class network was divided.

Class Address Range Total Hosts Number of blocks
A 0-127.XXX.XXX.XXX 16.7 Million 128
B 128.0.0.0-
191.255.255.255
65.5 Thousand 16,384
C 192.0.0.0-
223.255.255.255
256 2 million
D & E 224.0.0.0-
255.255.255.255
N/A N/A

I also listed the Classes D & E which are out of the scope of this article. Class D networks are for multicast and class E have been reserved.

There is something significant about the addresses for a Class A, B, and C Block. If you were to convert the decimal value of each class to binary you can see that there is a pattern in the most significant bits. See table below:

Class First 4 bits
A 0XX
B 10X
C 110

Although this pattern made it immediately obvious to routers what type of address block they were dealing with, it was also very innefficient with the address space.

Enter the Subnet Mask

Similar to the first 3 bits of an IP address that make a class, the subnet mask is now used instead to determine the size of an address block. Most people are familiar with an address followed by a subnet mask of 255.255.255.0 Calculated out, this subnet mask allows for up to 254 hosts. So if the address of a computer is 63.26.15.5 and the subnet mask is 255.255.255.0 there are 253 other addresses on this network block ranging from 63.26.15.1 - 63.26.15.254 (the .0 and .255 addresses are reserved and cannot be asigned to a network host).

From this a newbie can easily surmise that an address of 45.52.75.10 with a subnet mask of 255.255.0.0 allows for 256 times 256 minus 2 addresses (65,534 addresses). These addresses range from 45.52.0.1 to 45.52.255.254 Again we subtract two from the total number because of those two reserved addresses that are at the beginning and end of the block.

Clue: Determining the number of hosts in your subnet is always done by caculating the number of bits used for the host address (there are 8 bits for a mask of 255.255.255.0 for example). Set 2 to the Nth power where N is the total number of host addrress bits, then subtract 2.
In other words (2^8) - 2=254.

Clue: All address blocks (subnets) will be 2 less of each power of 2: 6, 14, 30, 62, 126, 254..... That is because in each address block we must reserve space for a broadcast and a network ID. The network ID is the first address (such as 192.168.0.0) and the broadcast is the last address (192.168.0.255)

Unfortunately if you leave yourself with only the ability to declare subnet masks using the number 255 or 0 you have very few options. The smallest subnet you know how to make is 254 hosts. The next article is where the real lesson begins!

However, if you are not up to learning how to calculate your own masks, we have also provided a subnet mask reference table. Just be warned that we will take to responsibility for your sleepless nights as you ponder how a subnet mask actually works.

No comments:

Post a Comment