When we think of a computer today, we almost inseparably link it with Internet access. What used to be a luxury, or painfully slow, is now an everyday thing within arm's reach, and fiber optics is no longer something futuristic but physically present in many homes. Network technologies are so popular and widespread that practically everyone uses them, and in such situations it turns out that most people don't know how it really works. Of course, let's not expect anyone to know the details of how a network cable is built or the Wi-Fi standard, since hardly any IT specialist knows that or needs it day to day. But there is one concept that often comes up in guides, when setting something up at home, or when talking to technical support.

Today we'll recall or learn what an IP address is and how it is built. We'll also look at why we use one address in a home or office network and a different one is visible from the outside. And why IPv4 is slowly becoming insufficient and why it is worth knowing at least something about IPv6.

What is an IP address?

In short, it is the address of every device connected to a network, though there are a few things you need to realize:

  • a device can have more than one IP address at the same time,
  • an IP address can change,
  • a device usually doesn't have an IP address that is unique worldwide,
  • a device is not always visible on the Internet under the IP address it has,
  • a "network" doesn't necessarily mean the Internet.

Now let's explain this calmly.

When you connect a device to a network with an Ethernet cable or Wi-Fi, you usually attach it to a router or another box that splits the signal. Only the router is connected to the Internet, that is, to the global network. This means our computer or smartphone (connected over Wi-Fi) usually doesn't operate directly out in the open. It has access to it, but it hides behind the router, which is its only contact with the world. The router usually connects many devices, which end up in one local network. Let's look at the following diagram:

Diagram showing two local networks (each has three computers with the addresses 192.168.1.2, 192.168.1.3, 192.168.1.4), and each is connected to a router with the local address 192.168.1.1 and a unique global address. Only the routers are connected to the Internet.

Here we see two local networks, each made up of three computers. The machines in this area have no direct access to the Internet. They have to rely on the router, which is usually additionally connected to the so-called ISP (Internet Service Provider), and only the ISP lets them communicate with the global village. Every visible device has its own IP address, but we notice that in local networks these addresses repeat, and some devices even have two. What is going on?

IP addresses can be public or private. The former, as the name suggests, are locations that are publicly accessible, and under this address a given computer or device is visible on the Internet (unless, of course, there are other protections). At the same time, this address can change. Home users know this well: they may have noticed that after every router restart they get a new global network address (you can check it, for example, on this site). We'll explain later in this article why that happens. Private addresses, on the other hand, are used only within a local network. That is why the same numbers can repeat in different local networks, but within one network they must be unique. Public addresses must be globally unique. And this is where the fun begins.

Since IP addresses can range from 0.0.0.0 to 255.255.255.255 (at least in pure theory, because in practice this range is smaller), there are 4,228,250,625 possible combinations. That has been far too few for a long time if every device in the world connected to the Internet is to have its own identifier (the MAC address, the number of a network card, has taken over that role to some extent, although relying on it has its drawbacks too). So something had to be done, and the solution was to allow sub-series within one numbering series, which is what local networks are. This meant setting aside ranges within which private addresses can be created. They are:

  • 10.0.0.0 - 10.255.255.255
  • 172.16.0.0 - 172.31.255.255
  • 192.168.0.0 - 192.168.255.255

Most often we deal with the third type of address, which allows networks of up to 65,025 devices, although in most real uses even a network for 256 devices is far too big. Why three separate pools of private addresses were created is covered in the context of the so-called IP address classes.

It is also worth knowing that if, say, the range from 192.168.1.0 to 192.168.1.255 (the one most often found in homes) gives 256 possibilities, that doesn't mean you can actually connect that many devices. Some addresses are reserved. Specifically:

  • 192.168.1.0, the first address of the subnet, is the subnet address itself, a kind of group address that is not assigned to any device.
  • 192.168.1.1 is, by convention, the router's address.
  • 192.168.1.255, the last one in the pool, is the so-called broadcast address for broadcast messages, that is, messages that cover the whole network.

So in such a typical local network, apart from the router, up to 253 individual devices can be connected. In smaller companies that is completely sufficient, but in larger ones it can already be a problem.

The router is a special case. On one hand it has a local address, because it belongs to the local network. On the other, it has to be reachable from the global network (at least in theory), so it also has a public address. By the way, the computers in the local network also have a public address, identical to the router's. You can even use this identifier to reach services running in the local network. This is done with a feature called port forwarding, which we won't cover here.

IPv4 address structure and subnetting

You have surely noticed already that an IP address (or rather an IPv4 address, which we'll come back to) is built in a specific way. It consists of four bytes or, as people often say, four octets, called that because each of them consists of eight bits. Because each part is one byte, no single part of an IP address can be greater than 255 (the range is 0-255).

The binary structure of an IP address is also related to dividing a network into subnets. This way, within one network you can create other, separate "children". That in turn is connected to the concept of the subnet mask, or so-called CIDR notation, which defines how many bits are set aside for the network itself and how many are left to hand out to the devices inside.

Let's show an example with the address 192.168.1.96, which in binary notation is written as follows:

11000000.10101000.00000001.01100000

Importantly, we can see a number of zeros at the end. This makes an easy division of the network possible. Next we need a mask, that is, an address or a number of bits that will form the base of the network. Masks are usually multiples of eight, that is 8, 16 or 24 (in standard notation: 255.0.0.0, 255.255.0.0 or 255.255.255.0). For the example, though, let's take something non-standard: the mask 255.255.255.240, or /28 in CIDR notation. The binary notation is as follows:

11111111.11111111.11111111.11110000

We see a lot of ones at the beginning and zeros at the end. It is these zeros that show us the bits of the divided address that will be reserved for the subnet. So the calculation looks like this:

Base IP address: 11000000.10101000.00000001.01100000
Separating the zeros: 11000000.10101000.00000001.0110 0000
Subnet mask: 11111111.11111111.11111111.1111 0000

Subnet range: from 11000000.10101000.00000001.0110 0000
to 11000000.10101000.00000001.0110 1111
The network ranges from 192.168.1.96 to 192.168.1.111, so it holds 16 minus 2 devices, including the router.

A little personal remark to finish: if you are a student of computer science at Poznań University of Technology, believe me, knowing how to divide networks into subnets will be extremely useful in the relevant course during your engineering studies. You can also always lean on calculators like these.

DHCP and a fixed address

I mentioned earlier that if we restart our router, we very often get a different public IP address each time. This is even easier to observe in a local network: the same connected devices can have different addresses on different days or at different hours (more precisely, after a network restart). This is handled by the so-called DHCP protocol (Dynamic Host Configuration Protocol), which removes the need to assign IP addresses by hand and does it automatically, using the pool of free slots at a given moment. By the way, the same principle works at the router level. Remember that when we connect a router to the Internet, it actually connects first to the ISP (our Internet provider), so you could say it is assigned an IP address in the provider's local network. That is a big simplification, as the mechanism is more complicated and goes beyond the scope not only of this article but also of the area programmers usually deal with.

Still, a dynamically assigned IP address is convenient, but there are situations where it is not enough and a fixed address is needed (or even required). In a local network this is not a problem: on the router you can force a specific address for the device with a given MAC address (which identifies the network card, so in short, the computer or smartphone). The trouble starts when our router is supposed to present itself on the Internet with an unchanging address. This is a service that Internet providers offer for an extra fee. If we want access to the local network from the outside, a fixed address is practically essential, because with port forwarding it lets us use certain services or, for example, share them with a client. To some extent it is possible without a fixed address too (for example through DDNS), but definitely harder.

IPv6

The addresses we have talked about so far belong to the so-called IPv4 protocol. As I wrote, it is a pool of over 4 billion addresses that ran out a long time ago. In fact, already in the early nineties it was known that it would not meet the global demand for devices connected to the network. That is why work on a new standard began long ago, and it was created. The problem is that it isn't used.

IPv6, as this is what we are talking about, has addresses written not as 4 bytes (32 bits) but as 16 bytes (128 bits). Since writing such constructs in decimal form would be quite problematic, they look very similar to MAC addresses. Namely, they use the hexadecimal system and colons separating two-byte groups. For example, one might look like this:

2001:0db8:85a3:0000:0000:8a2e:0370:7334

What's more, groups made up only of zeros can be omitted, which shortens the notation significantly. All right, but then why does IPv4 still rule? It turns out that infrastructure and Internet providers are to blame. Because for years everything was adapted to IPv4, when IPv6 arrived the world was as ready for it as Polish road crews are for winter. In other words, it wasn't. As a result, too small a share of ISPs support "sixes", which makes them hard to use in practice. There is a way to translate between the two protocols, but most likely you simply have support for these longer addresses turned off. You can check it, for example, here. For a longer explanation of this addressing, see Wikipedia or the documentation of the Mikrus server services, which use this form and explain why.

How do I check my local IP address?

It is fairly simple if you use the terminal, and don't worry, you don't need to be a programmer for it. Three commands will interest you. First I'll give the Windows versions, but above all I should mention how to open the console in this system: use "Run" (WIN + R -> cmd -> ENTER).

The three popular commands that may interest us are:

  • ipconfig checks the settings of our network cards (wired and wireless interfaces separately), including the IP address. If we add /all, we get more information, including MAC addresses (physical address).
  • ping [domain name or IP address] queries another device on the network and lets you test the connection. It is often useful if we suspect we have lost network access. Some devices block pings (handled by the ICMP protocol) even though they themselves are perfectly visible on the network.
  • tracert [Internet address] is a more interesting version of the previous command, which lets you trace the route from our computer to, say, a Google server. For some people it is an eye-opener how many stops a message makes along the way.

On Linux these commands are ifconfig (or ip a), ping and traceroute, respectively.

Is IP always related to networks?

Finally, it is worth mentioning that the "IP" we have been discussing here stands for Internet Protocol. For many people the meaning of this abbreviation is obvious, and they don't even realize that in a sister industry these two letters mean something completely different. I mean the video game or film industry and the term Intellectual Property. People often say that "a given IP belongs to company X", which should be read as owning a given brand. It is good to know this when browsing materials on the Internet.

Summary

This article was meant to gently introduce beginners to the world of IP addresses and make them aware that such a thing exists at all and can be useful, for example when contacting technical support or when expanding your own home or company network. Such knowledge is often invaluable and lets you, for example, better understand what you can configure in a router.

Best regards and thank you, Jakub Rojek.