Skip to content
Velloreth
Technology 3 min read

IP Addresses Explained: IPv4, IPv6 and Subnets

An IP address identifies a host on a network. Learn IPv4, IPv6, the subnet mask, CIDR notation, and the private ranges.

By

What an address is

A numeric label that identifies a host on a network.

It has two parts:

  • The network part, which identifies the subnet
  • The host part, which identifies the device

The subnet mask says where the split is.

IPv4

32 bits, written as four octets.

192.168.1.10

Each octet is 0 to 255, so the space is about 4.3 billion addresses.

The space is exhausted, which is why NAT and IPv6 exist.

IPv6

128 bits, written as eight groups of hexadecimal digits.

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

The shorthand removes a leading zero and collapses one run of zeros.

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

The space is effectively unlimited.

The benefits:

  • No NAT
  • A simpler header
  • Stateless autoconfiguration
  • A built-in checksum removal

The subnet mask

A value that says which bits are the network part.

MaskCIDRAddresses
255.255.255.0/24256
255.255.0.0/1665,536
255.0.0.0/816,777,216
255.255.255.128/25128
255.255.255.192/2664

A /24 means the first 24 bits are the network and the last 8 are the host.

Two addresses are reserved in each subnet: the network address and the broadcast address.

So a /24 holds 254 usable hosts, not 256.

CIDR notation

An address and a prefix length.

192.168.1.0/24

The number after the slash is the count of network bits.

It replaced the class-based system, which had only three sizes.

A subnet of any size is possible, which is the point.

The private ranges

RangeCIDRUse
10.0.0.0 – 10.255.255.25510.0.0.0/8a large private network
172.16.0.0 – 172.31.255.255172.16.0.0/12a medium private network
192.168.0.0 – 192.168.255.255192.168.0.0/16a home network
fc00::/7IPv6 private

They are not routable on the public internet.

A router translates them to a public address with NAT.

The special addresses

AddressMeaning
127.0.0.1loopback, this machine
0.0.0.0any interface, or an unspecified address
169.254.0.0/16link-local, when DHCP fails
255.255.255.255the local broadcast
::1the IPv6 loopback

A 169.254 address means the device did not get a DHCP lease.

NAT

Network Address Translation.

It rewrites the source address of an outgoing packet to the router’s public address.

It tracks the connection, so the reply can be routed back.

It is why a home network with many devices needs one public address.

It is a workaround for the IPv4 shortage, and it breaks an inbound connection unless a port is forwarded.

The tools

ip addr show          # the local addresses
ip route              # the routing table
ping 8.8.8.8          # reachability
dig example.com       # the DNS resolution
traceroute example.com # the path
ss -tulpn             # the listening ports

ip replaces ifconfig on a modern Linux.

Common mistakes

A /24 assumed to hold 256 hosts. Two are reserved.

A private address expected to be reachable. It is not routable.

A 169.254 address ignored. DHCP failed.

A subnet that overlaps. A routing conflict.

A hardcoded IP. It changes.

NAT assumed to be a firewall. It is not.

IPv6 disabled. A modern network needs it.

A /32 on a host. It is a single address.

A broadcast address assigned to a host. It is reserved.

No reverse DNS. A log is hard to read.

A quotable summary

An IP address identifies a host on a network, with a network part and a host part divided by the subnet mask. IPv4 is 32 bits and exhausted, IPv6 is 128 bits and effectively unlimited, and CIDR notation writes the prefix length as /24. The private ranges 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 are not routable on the public internet, and NAT is the workaround that lets a home network share one public address.

For the related topics, see dns-explained and how-cdns-actually-work. For the broader context, http-vs-https and ssh-and-keys-guide.

Frequently asked questions

What is an IP address?
A numeric label that identifies a host on a network, so packets can be routed to it. IPv4 is a 32-bit number written as four octets, and IPv6 is a 128-bit number written as eight groups of hexadecimal digits. An address has a network part and a host part.
What is a subnet mask?
A value that says which bits of an address are the network part and which are the host part. A /24 mask means the first 24 bits are the network and the last 8 are the host, so the subnet holds 256 addresses. The mask is written in CIDR notation as a prefix length.
What is CIDR notation?
Classless Inter-Domain Routing notation, which writes an address and a prefix length, such as 192.168.1.0/24. The number after the slash is the count of network bits. It replaced the older class-based system and it allows a subnet of any size.
What are the private IP ranges?
10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 for IPv4, and fc00::/7 for IPv6. They are not routable on the public internet, so they are used inside a home or a corporate network behind a router that translates them.
What is the difference between IPv4 and IPv6?
IPv4 is 32 bits and provides about 4.3 billion addresses, which are exhausted. IPv6 is 128 bits and provides an effectively unlimited space. IPv6 also removes NAT, simplifies the header, and supports stateless address autoconfiguration.
What is NAT?
Network Address Translation, which rewrites the source address of an outgoing packet to the router's public address and tracks the connection so the reply can be routed back. It is why a home network with many devices needs only one public address, and it is a workaround for the IPv4 shortage.