5.2 The Internet Layer

5.2 The Internet Layer

The Internet as we know it is based on the Internet Protocol, version 4 (IPv4). The basic idea is that each computer on the Internet has a numeric IP address in the form of a.b.c.d, where a and d are one-byte numbers from 1 to 254, and b and c are one-byte numbers from 0 to 255. Technically, an IP address is just a four-byte (32-bit) number, but it's usually easiest to deal with the address as a dotted-quad sequence of decimal numbers, like, instead of something ugly like the hexadecimal 0x0A170225.

A subnet is a group of IP addresses in some (hopefully) regular order. For example, the hosts between and could comprise a subnet, or all of the hosts between and could also be a subnet.

Subnets are important because they determine how your packets move between different machines. To communicate with another computer, your machine must know that other computer's IP address. If the destination is on your local area network's subnet, your system can send the data directly to that host, but if not, your machine probably has to send it to a gateway (or router) that transmits your data across another network on its way to the final destination.

5.2.1 More on Subnets

A subnet mask defines a subnet; for example, the subnet mask for is In pure binary form, the mask "covers" the bits in an address that are common to the subnet. For example, here are the binary forms of and        00001010 00010111 00000010 00000000    11111111 11111111 11111111 00000000

Now, let's "cover" the bits in with the 1s in by marking these bits in bold:        00001010 00010111 00000010 00000000

Look at the bits that aren't in bold. You can set any number of these bits to 1 to get a valid IP address in this particular subnet (with two exceptions: all 0s and all 1s).

Putting it all together, you can see that a host computer with an IP address of and a subnet mask of can directly communicate with other computers that have IP addresses beginning with 10.23.2 (to talk to the rest of the Internet, your computer needs to use a gateway). You can denote this entire subnet as

If you're lucky, you will deal only with easy subnet masks like or, but you may be unfortunate and encounter stuff like, where it isn't quite so simple to determine the set of addresses that belong to the subnet. It helps to know that 192 is 0xC0 in hexadecimal, from which you should be able to figure out what addresses belong to such a subnet. If you aren't familiar with conversion between decimal, binary, and hexadecimal formats, you should probably learn now. The dc (desk calculator) program has excellent facilities for converting between different radix representations.

A common shorthand for subnet masks is to identify the number of bits at the start of the subnet mask that have a value of 1. For example, contains 24 1-bits to start the 32-bit sequence, so you can write the earlier example of as Table 5-1 shows several example subnet masks.

Table 5-1: Subnet Masks

Long Form

Short Form






Therefore, to specify, you can use