# Internet protocol

Each device connected to the internet has a unique identifier. Most networks today, including all computers on the internet, use the **TCP/IP a**s a standard to communicate on the network. In the TCP/IP protocol, this unique identifier is the **IP Address**. The two kinds of IP Addresses are **IPv4**and **IPv6**.

## IPv4 vs IPv6 <a href="#id-3a9d" id="id-3a9d"></a>

**IPv4** uses 32 binary bits to create a single unique address on the network. An IPv4 address is expressed by four numbers separated by dots. Each number is the decimal (base-10) representation for an eight-digit binary (base-2) number, also called an octet.

![](https://miro.medium.com/max/1280/1*T-XFf3kOvko_are9ayCJKg.png)

**IPv6** uses 128 binary bits to create a single unique address on the network. An IPv6 address is expressed by eight groups of hexadecimal (base-16) numbers separated by colons. Groups of numbers that contain all zeros are often omitted to save space, leaving a colon separator to mark the gap .

![](https://miro.medium.com/max/1400/1*ByM8gaytcWsdiSpOkzYuAA.png)

IPv6 space is much larger than the IPv4 space due the use of hexadecimals as well as having 8 groups. Most devices use IPv4. However, due to advent of IoT devices and the greater demand for IP Addresses, more and more devices are accepting IPv6.

IPv4 addresses are normally expressed in dot-notation `xxx.xxx.xxx.xxx`where `xxx` is a value from 0 to 255. But another way to express them is as a 4-tuple of *octets*, which is an 8-bit segment since 2⁸=256. Here is the same IPv4 address in both dot-notation and 4-tuple octet.

```
172.217.6.3610101100 11011001 00000110 00100100
```

### IPv6 Addresses <a href="#id-737a" id="id-737a"></a>

IPv6 addresses are normally expressed in colon-notation as `xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx` where `xxxx` is a hexadecimal value. We can express them as an 8-tuple of 16-bit segments. Here is the same IPv6 address as an 8-tuple of 16 bits.

```
2001:0db8:0012:0001:3c5e:7354:0000:5db10010000000000001 0000110110111000 0000000000010010 0000000000000010
0011110001011110 0111001101010100 0000000000000000 0101110110110001
```

Note there are only 2³² possible IPv4 addresses but 2¹²⁸ possible IPv6 addresses. There is then a [one-to-one but not onto mapping from IPv4 to IPv6 addresses](https://stackoverflow.com/questions/1555591/how-to-convert-an-address-from-ipv4-to-ipv6). The Internet is (gradually) transitioning to IPv6 addresses so it can support more networked devices, without having to resort to [NAT](https://en.wikipedia.org/wiki/Network_address_translation)-ing.

### Network Prefix and Host Identifier <a href="#id-9b15" id="id-9b15"></a>

The Internet is not a single large network, but rather a collection of networks. One of these *networks* may be a college campus network; another of these *networks* may be a metro-wide ISP’s *network*, and they connect to each other through [internet exchange points](https://en.wikipedia.org/wiki/Internet_exchange_point).

IPv4 addresses are comprised of two parts. The first part is the *network prefix*, which identifies the network the address belongs to. The second part is the *host identifier*, which identifies the host within that network.

Where the *network prefix* ends and where the *host identifier* begins depends on the *class* of the IPv4 address.

### IPv4 Address Classification <a href="#id-5e33" id="id-5e33"></a>

There are 5 classes of IPv4 addresses, labeled *A* through *E*. The class of the IP address is determined by the first 4 bits.

* Class A — IP addresses are in this class if their first bit is a `0.` In dot-notation, this is the range `0.0.0.0` to `127.255.255.255` . The first 8 bits represent the *network prefix* and the rest represents the *host identifier*. For example, `127.42.13.69` has *network prefix* `127` and *host identifier*`42.13.69` .
* Class B — IP addresses are in this class if their first two bits are `10` . In dot-notation, this is the range `128.0.0.0` to `191.255.255.255` . The first 16 bits represent the *network prefix* and the rest represent the *host identifier*. For example, `129.42.13.69` has *network prefix* `129.42` and *host identifier* `13.69` .
* Class C — IP addresses are in this class if their first three bits are `110` . In dot-notation, this is the range `192.0.0.0` to `223.255.255.255` . The first 24 bits represent the *network prefix* and the rest represent the *host identifier*. For example, `196.13.42.69` has *network prefix* `196.13.42` and *host identifier* `69` .
* Class D — IP addresses are in this class if their first four bits are `1110` . In dot-notation, this is the range `224.0.0.0` to `239.255.255.255` . These addresses are used for multi-casting protocols (ie. when a single packet can be sent to multiple hosts in one action)
* Class E — IP addresses are in this class if their first four bits are `1111` . In dot-notation, this the range `240.0.0.0` to `255.255.255.255` . These addresses are reserved for future and experimental use.

## Reserved IP Addresses <a href="#id-57b4" id="id-57b4"></a>

Some IPv4 addresses are reserved for specific uses, namely l*oopback IPs* and*Private IPs*.

### Loopback IPs <a href="#afd3" id="afd3"></a>

The IPv4 address range `127.0.0.0` to `127.255.255.255` is reserved for *looping back*, which is when a host sends a network request to itself. Sometimes we want a program on a host to connect back to itself for debugging or development purposes.

### Private IPs <a href="#id-050b" id="id-050b"></a>

The IP ranges `10.0.0.0 — 10.xxx.xxx.xxx` , `172.16.0.0 — 172.31.xxx.xxx` , and `192.168.0.0 — 192.168.xxx.xxx` are designated private network addresses, meaning they can be assigned to computers which must go through the [Network Address Translation (NAT) protocol](https://en.wikipedia.org/wiki/NAT_Port_Mapping_Protocol) to connect to the Internet. It’s *private IPs* that make it possible for over 8 billion devices to connect with only about 4 billion IPv4 address (2³² =\~ 4 billion).

## Subnets <a href="#ca08" id="ca08"></a>

A *subnetwork* or *subnet* is basically a smaller network within a larger network. The process of partitioning a network into *subnets* is called *subnetting.* Each computer on the same *subnet* can communicate directly with each other but not directly with computers on a different *subnet*. This is usually done for security or performance reasons.

As stated earlier, IPv4 addresses are comprised by a *network prefix* and *host identifier*. *Subnetting* is done by partitioning the *IP address* into three parts, a *network prefix*, a *subnet number*, and *host identifier*. The specification of where these numbers start and end in the *IP address* is done through a *net mask.*

### Netmasks <a href="#id-8075" id="id-8075"></a>

A *netmask* is used to describe which segments of the *IP address* are the *network prefix* and *host identifier*. Namely, the *netmask* is a 4-tuple of octets, that specify which segment of the *IP address* as part of the *network prefix* by using a `1` for every position that corresponds to a *network* *prefix*, and `0`otherwise. In other words, we get the *network prefix* through bit-wise multiplication of the *IP address* and the *netmask*.

For example, the *default netmask* for Class A *IP addresses* would be \
`11111111 00000000 00000000 00000000` \
as binary or `255.0.0.0` in dot-notation.

The *default netmask* for Class B *IP addresses* would be \
`11111111 11111111 00000000 00000000` \
as binary or `255.255.0.0` in dot-notation.

The *default netmask* for Class C *IP addresses* would be \
`11111111 11111111 11111111 00000000` as binary \
or `255.255.255.0` in dot-notation.\ <br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tkssharma-devops.gitbook.io/devops-training/basic-networking/internet-protocol.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
