IP Addresses

Understand what IP addresses are, how IPv4 and IPv6 are written, why the numbers stop at 255, and how public and private addresses differ.

~21 min Beginner

What an IP address is

An IP address (Internet Protocol address) is a number assigned to a device on a network. Data needs a destination, and the IP address is that destination.

It does two jobs at once:

  • It identifies the device, so packets can be addressed to it.
  • It shows which network the device is on, so routers know where to send those packets.

A device that is connected to several networks, for example a laptop with both WiFi and Ethernet, has a separate IP address on each connection.

IPv4: the classic format

An IPv4 address is four numbers between 0 and 255, separated by dots:

192.168.1.100

Each number is one byte (8 bits), so the whole address is 32 bits long. That allows about 4.3 billion different addresses (232). When IPv4 was designed in the early 1980s that looked like more than enough. With billions of phones, laptops, TVs and sensors, it was not, and the supply of IPv4 addresses ran out.

Why the numbers stop at 255

Each of the four numbers is one byte, which is 8 bits, and each bit is either 0 or 1. Eight bits can form 28 = 256 different values, from 0 to 255. That is why 256 or 300 can never appear in an IPv4 address.

Here is 192.168.1.100 the way a computer stores it:

192      168      1        100
11000000 10101000 00000001 01100100

The dotted numbers are only a more readable way to write those 32 bits. This matters in the subnetting lesson, where the split between the network part and the device part of an address happens on a bit boundary.

IPv6: the bigger fix

IPv6 addresses are 128 bits long. They are written in hexadecimal (digits 0 to 9 and letters a to f), in eight groups separated by colons:

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

128 bits gives about 3.4 x 1038 addresses, so running out is not a realistic worry. To make an address shorter, you can drop leading zeros in each group and replace one run of all-zero groups with :::

2001:db8:85a3::8a2e:370:7334

You can use :: only once in an address, otherwise nobody could tell how many zero groups each one stands for. Most networks today run IPv4 and IPv6 side by side.

Public and private addresses

Some IPv4 ranges are reserved for private use inside homes and offices. Routers on the internet never forward them, so every home and company can reuse the same ranges without conflict:

10.0.0.0    to 10.255.255.255
172.16.0.0  to 172.31.255.255
192.168.0.0 to 192.168.255.255
  • The devices in your home have private addresses such as 192.168.1.23.
  • Your router has one public address from your internet provider. All your devices share it through NAT, which the routers lesson explains.

Any address outside those ranges, and outside the special ranges on the next cards, is public and can be reached from anywhere on the internet. Note that 172.32.0.1 is public, because the private block ends at 172.31.255.255.

Static or dynamic

A device can get its address in two ways:

  • Dynamic: a DHCP server hands out an address automatically. Almost every phone and laptop works this way, and the address can change over time.
  • Static: a person types in a fixed address, or reserves one for the device. This is normal for printers, servers and routers, because other devices need to find them at the same address every time.

The public address your provider gives you is usually dynamic as well. It can change when the router restarts unless you pay for a fixed one.

To see your public address from a terminal, ask a web service:

curl ifconfig.me

Compare it with the private address from ip addr. They are different, and NAT is what links them.

Special addresses worth knowing

  • 127.0.0.1 is the loopback address. It always means "this computer", and traffic sent to it never leaves your machine. Developers use it to test programs running locally. The name localhost points to it.
  • 0.0.0.0 usually means "any address" or "no address yet".
  • 169.254.x.x is a self-assigned address. A device gives itself one when it asked for an address and no DHCP server answered.
If you see a 169.254 address on your own machine, that is a clue: the device could not reach a DHCP server, so the problem is the connection to the network, not the website you are trying to open.

Finding your own address

ip addr          # Linux
ifconfig         # older Linux and macOS
ipconfig         # Windows

Look for the line that starts with inet on Linux and macOS, or IPv4 Address on Windows. On Linux the output looks like this:

2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> ...
    inet 192.168.1.23/24 brd 192.168.1.255 scope global wlan0

Here 192.168.1.23 is the address and /24 describes the size of the network, which the next lesson covers. This is your private address. To see your public one, run curl ifconfig.me or search "what is my IP" in a browser. The two will differ.

Sign up to track your progress Mark lessons as read and pick up where you left off Sign up free to unlock this practice Your first practice lesson is free to try. Create an account to unlock the rest and save your progress