3.1 Introduction to hosts and subnets

IP addresses are used to identify devices on a network. To communicate with other devices over a network, an IP address must be assigned to each network device (including computers, servers, routers, printers). Such devices on the network are called hosts .

Network equipment also has its own numbers. And all computers that are served by specific network equipment are called subnet . Each subnet has a pattern by which network equipment assigns IP addresses to its subnets. Such a pattern is called a subnet mask .

Subnet masks allow you to divide one network into several subnets, and also set the maximum number of sponsored hosts.

Introduction to IP addresses

An IP address consists of four parts, written as dotted decimal numbers (for example, Each of these four parts is called an octet . An octet is eight binary digits, such as 00001111.

Thus, each octet can take the binary value from 00000000to 11111111or from 0to 255decimal.

IP address structure

The first part of the IP address is the network number, the other part is the host ID. Together they form a unique host IP address. The shorter the network number, the more hosts it can fit. If the network number occupies 3 bytes, then only one byte will remain per host number (the maximum 255of hosts in the network).

The network number is used by routers (routers, routers) to forward packets to the desired networks, while the host ID identifies the specific device on that network to which the packets should be delivered.

Network and host number example

The following figure shows an example of an IP address where the first three octets ( 192.168.1) are the network number and the fourth octet ( 16) is the host ID.

Network and host number example

The number of binary digits in an IP address that are per network number and the number of digits in an address that are per host ID can be different depending on the subnet mask.

3.2 Subnet masks

Private IPs

Every host on the Internet must have a unique address. The exception is IP addresses within local networks.

If you have your own local network in your office, then its computers will have their own non-unique IP addresses. However, if it is a computer directly connected to the Internet, or a server, then it must have a publicly unique IP address.

There is a special organization (IANA) that deals with the distribution of IP addresses. ISPs buy IP addresses from it in blocks (subnets) and then sell them to their customers. So if you pay for a white IP address, then everything is in order (the provider also pays money for it).

Also, IANA has identified several subnets that are commonly used for non-public local area networks. Since these subnets are non-public, they can be used by anyone for any purpose. There are three such subnets: large, medium and small.

The following three blocks of IP addresses are reserved for them:


The IP addresses of these private subnets are sometimes referred to as "gray" addresses.

Subnet masks

In order to determine which bits of an IP address refer to the host number and which bits refer to the subnet number, a so-called subnet mask is used .

Let's say you have an IP address written in binary:

11110101  01010101 11111111 00000001

The bits responsible for the network number are marked in red, the bits responsible for the host number are marked in green. Yes, that's also possible. There is no hard binding to bytes.

The subnet mask will be called such a number, where the subnet bits will correspond to ones, and the host bits will correspond to zeros. Subnet mask example for the previous address:

11111111  11111111 11110000 00000000

All subnet bits are equal 1, all host bits are equal 0.

An example of extracting the network number and host ID in an IP address:

1st octet: (192) 2nd octet: (168) 3rd octet: (1) 4th octet: (2)
IP address (binary) 11000000 10101000 00000001 00000010
Subnet mask (binary) 11111111 11111111 11111111 00000000
Network number 11000000 10101000 00000001
Host ID 00000010

Subnet masks always consist of a series of consecutive 1's, starting with the leftmost bit of the mask, followed by a series of consecutive 0's for a total of 32bits.

The subnet mask can be defined as the number of bits in the address that represent the network number (the number of bits with a value of " 1"). For example, " 8-bit mask" is a mask in which 8the bits are ones and the rest of 24the bits are zeros.

Subnet masks are written in dotted decimal notation, just like IP addresses. The following examples show the binary and decimal notation of 8-bit, 16-bit, 24-bitand 29-bitsubnet masks.

Subnet masks:

Decimal Binary 1st octet: Binary 2nd octet: Binary 3rd octet: Binary 4th octet:
8-bit mask 11111111 00000000 00000000 00000000
16-bit mask 11111111 11111111 00000000 00000000
24 bit mask 11111111 11111111 11111111 00000000
29-bit mask 11111111 11111111 11111111 11111000

3.3 DHCP

Inside the local network, there can be both static and dynamic IP addresses. System administrators can assign static addresses to computers. Dynamic ones are assigned to computers automatically using the DHCP service .

Dynamic Host Configuration Protocol (DHCP) is an application protocol that allows network devices to automatically obtain an IP address and other parameters necessary to operate on a TCP/IP network.

After the computer has booted up, the operating system accesses the DHCP server (usually built into the router) and receives an IP address (and other necessary parameters) from it. This avoids manual configuration of computers on the network. This approach is used in most local networks.

IP address distribution

The DHCP protocol provides three ways to allocate IP addresses:

Manual distribution . In this method, the network administrator maps the hardware address (MAC address) of each computer to a specific IP address. In fact, this method of address allocation differs from manually configuring each computer only in that address information is stored centrally (on the DHCP server) and therefore it is easier to change it if necessary.

Automatic distribution . With this method, each computer is allocated an arbitrary free IP address from the range defined by the administrator for permanent use.

dynamic distribution . This method is similar to automatic distribution, except that the address is given to the computer not for permanent use, but for a certain period. This is called an address lease. After the lease expires, the IP address is again considered free and the client is obliged to request a new one (however, it may turn out to be the same). In addition, the client himself can refuse the received address.

Advanced DHCP services are able to automatically update DNS records corresponding to client computers when new addresses are allocated to them. This can be useful when you have a large corporate network that uses internal DNS for server and computer names.

DHCP Options

In addition to the IP address, DHCP can also provide the client with additional parameters necessary for normal network operation. These options are called DHCP options. There are many, but you only need to know a few of them.

Some of the most commonly used options are:

  • default router IP address;
  • Subnet mask;
  • DNS server addresses;
  • DNS domain name.

3.4 localhost and

There are several IP addresses that are useful to know. For example, the IP address of your router. Another IP address that is useful to know is we will talk about it in a little more detail.

What is

The IP address known as the loopback address, but you can see it as localhost . When you point your browser to, it tries to connect to the computer you are using right now. This is handy when you want to connect to a server on your computer. special among IP addresses. As a rule, the IP address is unique for each computer both on the local network and on the Internet. However, always points to the computer you are currently using, no matter what.

For example, you set up a server on your work computer and you can connect to it by typing your browser at work. However, when you get home and type in, you'll connect to your home computer instead. To connect to a work computer, you will need its public IP address.

What is localhost?

localhost is actually a domain name for there is no difference between localhost. You can write it this way and that way, as you like.

You can think of localhost as the "name" for an address, just as "www.google.com" is the "name" for a Google IP address. However, when you visit www.google.com, it must go through a DNS server so that your computer can determine which IP address matches the name.

Localhost doesn't need a DNS server because your computer already knows you want to connect to it. This way you can use localhost even if you don't have an internet connection.