IP Basics - Routing 101

IP subnetting: Base-2 math
An IP subnet is a collection of network addresses which can communicate directly with each other without having to refer to a router to accomplish the communication. In other words, the media-protocol drivers support direct communication between all systems in the same subnet. Transmitting data between two separate subnets requires a router, often called a gateway in this context. To determine whether or not two systems are in the same subnet, do the following:

Perform a binary AND of the IP address of machine A and the subnet mask of machine A. Now do the same for machine B. If the resulting network addresses are identical for both machines, then these machines can speak over TCP/IP to each other without using a gateway.

If this is Greek to you, you should review the remainder of this section. It introduces enough base–2 math to get you started with IP addresses, the subnet mask, what is meant by a network and broadcast address, and how to calculate them.

The IP Address & Base–2 Mathematics
An IP address is a collection of 32 bits, divided into four groups of 8 bits for convenient presentation in the form of 4 unsigned integers (really, decimals, since the presentation is in base-10). Each grouping of 8 bits can be expressed as a value between 0 and 255. Almost everyone is familiar with the dotted-decimal notation used for 32-bit IP addresses: w.x.y.z, where the value of w,x,y,z is between 0 and 255. This is done primarily for humans; the computers couldn't care less about the decimal values. Here is an example IP address:

As you see it (base–10): 215.38.181.126

As the computer sees it (base–2 or binary): 11010111001001101011010101111110

Split into 4 groups of 8 bits: 11010111 00100110 10110101 01111110

Each bit represents a successively greater power of two as you move from right to left. Note that the powers of two, which are listed below, start at 20.

 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1

A "1" in a given bit position indicates that the corresponding power of two counts towards the final value. A "0" in a given bit position means to ignore that position. If we label the bit positions b7–b0 (moving from left to right), we can write out a formula for our binary-to-decimal conversion.

128*b7 + 64*b6 + 32*b5 + 16*b4 +8*b3 +4*b2 +2*b1 +1*b0

Thus, the binary-to-decimal conversion of 11010111 works as follows:

 128*1 + 64*1 + 32*0 + 16*1 + 8*0 + 4*1 + 2*1 + 1*1 128 + 64 + 0 + 6 + 0 + 4 + 2 + 1

which equals 215.

As you can see, the bit positions where there was a "1" contributed to the final value; the positions containing "0" did not. Converting the other three values in our initial example (oftentimes referred to as octets, as they are groupings of 8, but most commonly known simply as bytes) yields:

00100110 =38
10110101 =181
01111110 =126

 Tip: Help with Base–2 Conversions If you are not accustomed to making these conversions (or counting in 2's), I encourage you to perform these conversions on your own so that you can be certain about how they work. Most scientific calculators can help, as will some calculator programs—notably calctool (written by Rich Burridge).

The reason the computer does not use the decimal representation is because it is easier only for humans. The hardware in the computer (and on the NIC) is designed to operate on bits. In fact, it can work only with bits. One good thing about bits is that digital hardware can do things with them incredibly quickly. Routers like speed and efficiency, so router admins get to work with bits.

To review, an IP address is 32 bits that are often represented as four groupings of 8 bits each. At least, that's the simple answer. The next section covers how these 32 bits can be split into network and address fields.