IPv4

Introduction

This article is about IPv4. The newer version of the protocol is described in IPv6.

IP is a protocol of the third (network) layer of the OSI model, the Network Layer.

RFC 760 was published in 1980. Addresses in the form we know today are not mentioned there explicitly yet.

An example of an IP address is 8.8.8.8

Dots split it into four parts, the octets, of 8 bits each. Each octet takes a value from 0 to 255.

Computer network image from www.aredel.com
Computer network
Image: rudalle.ru

203.0.113.10/24

/24 is the Subnet Mask or simply the netmask.

The mask splits the address into two parts: the Network Portion (the network address) and the Host Portion (the host address).

The size of the Network Portion equals the mask.

203.0.113 is the so-called Network Portion

.10 is the Host Portion

How this split works is explained in the Subnet Mask section.

An IP address means little without its mask (example)

To find out your own IP address, use this page

Binary representation
203 0 113 10
11001011 00000000 01110001 00001010
8 bits 8 bits 8 bits 8 bits

Until 1995 Classful Addressing was used.

After 1995, Classless Addressing.

Computer network image from www.aredel.com
Computer network
Image: rudalle.ru

Subnet Mask

RFC 950 of 1985 is the first to mention masks. In this document both IP addresses and masks are already shown in the form we know today.

203.0.113.10/24

In this example the mask is 24. That is, it takes exactly three octets of eight bits.

So the first three octets hold the network address, and the last one the address of the host inside the network.

If the mask were 16, the address would be split in half: the first half is the network, the second half is the host.

So 24 bits are given to the network part of the address and 8 bits to the hosts (the term nodes is also used).

203.0.113 is the so-called Network Portion

.10 is the Host Portion

A smaller mask makes the Host Portion larger at the expense of the Network Portion.

IP address and mask 255.255.255.0
IP in decimal 203 0 113 10
IP in binary 11001011 00000000 01110001 00001010
Mask in binary 11111111 11111111 11111111 00000000
Mask in decimal 255 255 255 0

The mask is split into octets too. The table puts the binary IP address and the binary mask one above the other.

If a bit of the address sits above a 0 of the mask, it belongs to the Host Portion.

If a bit of the address sits above a 1 of the mask, it belongs to the Network Portion.

According to RFC 1519 the mask must consist of consecutive ones with no zeros between them.

An implementation following these rules should also be generalized, so that an arbitrary network number and mask are accepted for all routing destinations. The only outstanding constraint is that the mask must be left contiguous. Note that the degenerate route 0.0.0.0 mask 0.0.0.0 is used as a default route and MUST be accepted by all implementations. Further, to protect against accidental advertisements of this route via the inter-domain protocol, this route should never be advertised unless there is specific configuration information indicating to do so.

Examples of valid masks:

10000000 00000000 00000000 00000000 # /1 11000000 00000000 00000000 00000000 # /2 11100000 00000000 00000000 00000000 # /3 … 11111111 11110000 00000000 00000000 # /12 11111111 11111111 00000000 00000000 # /16 11111111 11111111 11111111 00000000 # /24 11111111 11111111 11111111 11111110 # /31

Examples of invalid masks with gaps:

10100000 00000000 00000000 00000000 11010000 00000000 00000000 00000000 11100001 00000000 00000000 00000000 … 11111111 11110001 00000000 00000000 11111111 11111111 11111101 11110100

The exception to this rule are the so-called wildcard masks, or inverse masks.

The smaller the mask, the more unique hosts the network can hold.

In a large local network you do not want to spend 24 bits on the network part and leave only 8 bits for the hosts.

Remember that 8 bits give only 256 unique values. The first one, .0, is reserved for the address of the network itself (the Network Address ), and the last one, .255, for the broadcast address (the Broadcast Address ); both are described below. That leaves only 254 unique IP addresses for hosts (the Host Address ).

To get more unique host addresses you need a different mask. For example

Mask 255.0.0.0
11111111 . 00000000 . 00000000 . 00000000
255 . 0 . 0 . 0

The mask 255.0.0.0 is the other way round: 8 bits for the network part and 24 bits for the host.

An example of an IP address with this mask

IP and mask 255.0.0.0
IP in decimal 10 . 0 . 0 . 10
IP in binary 00001010 . 00000000 . 00000000 . 00001010
Mask in binary 11111111 . 00000000 . 00000000 . 00000000
Mask in decimal 255 . 0 . 0 . 0

The border between the Host Portion and the Network Portion does not have to fall on an octet boundary.

IP and mask 255.255.240.0
IP in decimal 10 . 0 . 0 . 10
IP in binary 00001010 . 00000000 . 00000000 . 00001010
Mask in binary 11111111 . 11111111 . 11110000 . 00000000
Mask in decimal 255 . 255 . 240 . 0

The IP address 10.0.0.10 from the previous example can belong to a host in a network with the mask 255.0.0.0 as well as with the mask 255.255.240.0

Let us see where the difference shows.

Take two IP addresses, 10.0.15.10 and 10.0.16.10.

With the mask 255.0.0.0

IP and mask 255.0.0.0
10.0.15.10 dec 10 . 0 . 15 . 10
10.0.15.10 bin 00001010 . 00000000 . 00001111 . 00001010
10.0.16.10 dec 10 . 0 . 16 . 10
10.0.16.10 bin 00001010 . 00000000 . 00010000 . 00001010
Mask in binary 11111111 . 00000000 . 00000000 . 00000000
Mask in decimal 255 . 0 . 0 . 0

The network part of the address takes only the first octet and is shown in bold, so it is easy to see that 10.0.15.10 and 10.0.16.10 are two neighbouring hosts in the same subnet.

Now the same addresses with the mask 255.255.240.0

IP and mask 255.255.240.0
10.0.15.10 dec 10 . 0 . 15 . 10
10.0.15.10 bin 00001010 . 00000000 . 00001111 . 00001010
10.0.16.10 dec 10 . 0 . 16 . 10
10.0.16.10 bin 00001010 . 00000000 . 00010000 . 00001010
Mask in binary 11111111 . 11111111 . 11110000 . 00000000
Mask in decimal 255 . 255 . 240 . 0

Look at the third octet, especially at its binary form.

None of the set bits of the address 10.0.15.10 fell into the network part (there are no bold ones).

So the host address of 10.0.15.10 stayed the same, but the network part of the IP address grew noticeably.

In 10.0.16.10 the one in the third octet fell into the network part. Only 1010 is left of the host address, and the subnet is now different from the subnet of 10.0.15.10

So now 10.0.16.10 and 10.0.15.10 are not neighbouring hosts of one subnet but hosts in different subnets.

Computer network image from www.aredel.com
Computer network
Image: rudalle.ru

Classful Addressing

If you have ever heard of class A, class B, C, D or E IP addresses, that was about the obsolete classful addressing (Classful Addressing).

Classless addressing is described in the CIDR section.

Classful addressing
Class IP address range
A 0.0.0.0 127.255.255.255
B 128.0.0.0 191.255.255.255
C 192.0.0.0 223.255.255.255
D 224.0.0.0 239.255.255.255
E 240.0.0.0 255.255.255.255

A, B and C are the so-called Unicast. These are the addresses used on the public internet today (except for the private addresses ). The principle is that one device talks to one device.

D is multicast. One device talks to several devices. It is not supported on the internet, but it is supported in large private networks for broadcasting meetings and so on.

Class A: the first 8 bits are always the network part

Class B: the first 16 bits are always the network part

Class C: the first 24 bits are always the network part

Class D: all 32 bits are always the network part

Types of IP addresses

By the value the Host Portion takes, addresses fall into three types

Network Address

The network address (Network Address or Network Prefix) is a unique identifier of a group of devices. Just as a street name is a unique identifier of all the houses on that street, but not of one particular house (unless, of course, the street has only one house).

In a network address all bits of the Host Portion are 0

Network address example
255.255.255.0 dec 255 . 255 . 255 . 0
255.255.255.0 bin 11111111 . 11111111 . 11111111 . 00000000

Broadcast Address

The broadcast address (Broadcast Address) is an identifier that points to all devices in the network.

In a broadcast address all bits of the Host Portion are 1

Broadcast address example
255.255.255.255 dec 255 . 255 . 255 . 255
255.255.255.255 bin 11111111 . 11111111 . 11111111 . 11111111

An example shows the difference. A postman is told to deliver a letter to the office of TopBicycle on Partnyorskaya Street and is given these instructions

Deliver to the company Company;Website;Type;Address TopBicycle;www.topbicycle.ru;Bicycles;Partnyorskaya Street

This is the counterpart of the network address. There can be many offices on Partnyorskaya Street. Where exactly to take the letter is not clear at once: the house number is needed too (in a network, the host address).

The next day the postman is told to deliver a notice about street repairs to every house and office on Partnyorskaya Street.

The notice is the same for all companies.

Deliver to all recipients Company;Website;Type;Address Aredel;www.aredel.com;IT;Partnyorskaya Street HeiHei;www.heihei.ru;Travel;Partnyorskaya Street TopBicycle;www.topbicycle.ru;Bicycles;Partnyorskaya Street Beget;www.beget.com;Hosting;Partnyorskaya Street

This is the counterpart of the broadcast address. If there were two offices on the street, the letters would go to both. If twenty, to all twenty. The postman does not need to know who is in which house: it is enough to walk down the street with the letters and enter every house in turn (in the order they stand on the street, not in the order of the list).

Host Address

The host address (Host Address) is an identifier that points to one particular device in the network.

A host address can have any combination of bits in the Host Portion except two: all zeros and all ones.

All zeros is the network address, all ones is the broadcast address. Everything else is a host address.

A network address in decimal notation does not have to end in 0

Take the address 10.128.224.64 with the mask 255.255.255.224.

To check whether an address is a network address, check whether its Host Portion holds only zeros.

The IP address alone is not enough for that: you need to look at it together with the mask to see what the Host Portion is

Network address example
IP in decimal 10 . 128 . 224 . 64
Mask in decimal 255 . 255 . 255 . 224
IP in binary 00001010 . 10000000 . 11100000 . 01000000
Mask in binary 11111111 . 11111111 . 11111111 . 11100000

The network part is in bold. Clearly only zeros are left in the host part, so this address is a network address

CIDR Notation

CIDR stands for Classless Inter-Domain Routing, that is, classless addressing.

RFC 1517, RFC 1518, RFC 1519, RFC 1520 of 1993.

Take the mask 255.255.255.0

Its first 24 bits are ones. Instead of writing 255.255.255 every time you can write

/24

The format is a slash followed by the length of the Network Portion

For example:

203.0.113.10/24

Private

Three address ranges are not used on the public internet.

10.0.0.0/8
172.16.0.0/12
192.168.0.0/16

Private IP Address Range
Start End Mask
10.0.0.0 10.255.255.255 /8
172.16.0.0 172.31.255.255 /12
192.168.0.0 192.168.255.255 /16

Avoid using the addresses 169.254.0.0/16

From 169.254.0.1 to 169.254.255.254 is the so-called Automatic Private IP Addressing (APIPA)

The address 127.0.0.1 is reserved for the Loopback Address

It means the address of your own computer. You could call it the home address.

In IPv6 it is written as ::1

Subnetting Networks

Take the IP address 10.0.0.0/8

10.0.0.0
255.0.0.0

The range of host addresses (not counting the ends):

10.0.0.0 - 10.255.255.255

N 00001010 00000000 00000000 00000000
B 00001010 11111111 11111111 11111111
M 11111111 00000000 00000000 00000000

RFC

INTERNET PROTOCOL RFC 791

TRANSMISSION CONTROL PROTOCOL RFC 793

HTTP RFC 2616

Requirements for Internet Hosts -- Communication Layers RFC 1122

Minimum number of bits

Bits, networks and hosts
Bits Networks Hosts
0 1 0
1 2 0
2 4 2
3 8 6
4 16 14
5 32 30
6 64 62
7 128 126
8 256 254
9 512 510
10 1024 1022

Article author: Andrei Olegovich