IP Addressing Explained: IPv4, IPv6, Private Ranges and CIDR
What is an IP address?
An IP address is a numeric label that identifies a device interface on a network so packets can be delivered to it. IPv4 addresses are 32 bits long and written as four decimal numbers, such as 192.168.1.25. IPv6 addresses are 128 bits long and written in hexadecimal. Part of every address identifies the network and the rest identifies the host.
IPv4 structure: 32 bits in dotted decimal
An IPv4 address is a 32-bit binary number. To make it readable, the bits are split into four groups of eight, called octets, and each octet is written as a decimal number from 0 to 255. That is why the format is called dotted decimal.
Decimal: 192 .168 .1 .25
Binary: 11000000 .10101000 .00000001 .00011001Thirty-two bits give 2 to the power 32 possible values, roughly 4.3 billion addresses. That sounds large, but it is far fewer than the number of connected devices, which is why private addressing, NAT and IPv6 exist. The TCP/IP model places IP at the internet layer, where it handles addressing and routing.
Key terms
- Network portion: the leading bits shared by every device on the same network.
- Host portion: the remaining bits that identify one interface within that network.
- Prefix length: the number of network bits, written after a slash, as in
/24. - Subnet mask: the same information in dotted decimal, for example
255.255.255.0for/24.
Network and host portions, CIDR and the default gateway
Take 192.168.1.25/24. The first 24 bits (192.168.1) are the network and the last 8 bits (25) are the host. Every device whose address starts with 192.168.1 sits on the same network and can talk directly through a switch. The all-zeros host value (192.168.1.0) is the network address and the all-ones value (192.168.1.255) is the broadcast address, so neither is given to a device.
CIDR (Classless Inter-Domain Routing) replaced the old class A, B and C system. Instead of fixed boundaries, any prefix length from /0 to /32 can be used, which lets networks be sized to fit. Splitting a block into smaller networks is covered step by step in the subnetting guide.
When a host sends a packet, it compares the destination with its own network. If the destination is local, it delivers the packet directly. If not, it sends the packet to its default gateway, usually the router interface on that network, such as 192.168.1.1. How routers then forward that packet is explained in routing and switching.
Public, private and special-purpose IPv4 ranges
Public addresses are globally unique and routed on the internet. Private addresses, defined in RFC 1918, can be reused inside any organisation but are not routed on the public internet.
| Range | Purpose | Where you see it |
|---|---|---|
| 10.0.0.0/8 | Private (RFC 1918) | Large enterprise and cloud networks |
| 172.16.0.0/12 | Private (RFC 1918), covers 172.16.0.0 to 172.31.255.255 | Corporate networks, container platforms |
| 192.168.0.0/16 | Private (RFC 1918) | Home and small office routers |
| 127.0.0.0/8 | Loopback | 127.0.0.1 always means this machine |
| 169.254.0.0/16 | Link-local (APIPA) | Self-assigned when no DHCP server answers |
| 100.64.0.0/10 | Shared address space for carrier-grade NAT | Some mobile and broadband connections |
Static addresses, DHCP and NAT in practice
A static address is typed in by an administrator and never changes. Servers, printers, routers and firewalls usually get static addresses (or DHCP reservations) so other systems can find them reliably. A dynamic address is leased from a DHCP server, which also hands out the subnet mask, default gateway and DNS servers. Laptops and phones normally use DHCP.
NAT (Network Address Translation) lets many private devices share one public address. The edge router rewrites the private source address and port of outgoing packets to its own public address and keeps a translation table, so replies return to the right device. NAT is not a security control on its own; filtering is the job of a firewall, as described in network security fundamentals.
IPv6 basics: 128 bits, hexadecimal and shortening
IPv6 addresses are 128 bits, written as eight groups of four hexadecimal digits separated by colons. Two rules make them shorter: leading zeros in a group can be dropped, and one run of consecutive all-zero groups can be replaced by ::. The double colon may appear only once in an address, otherwise its length would be ambiguous.
Full: 2001:0db8:0000:0000:0000:ff00:0042:8329
Shortened: 2001:db8::ff00:42:8329
Loopback: ::1
Link-local: fe80::5054:ff:fe12:3456fe80::/10is link-local: every IPv6 interface has one, and it works only on the local link.::1is the IPv6 loopback, the equivalent of127.0.0.1.2001:db8::/32is reserved for documentation and examples.- A typical LAN uses a
/64prefix, and hosts often configure themselves with SLAAC or DHCPv6.
How to check your IP address on Windows and Linux
- On Windows, open Command Prompt or PowerShell and run
ipconfig; add/allto see the DHCP server, DNS servers and MAC address. - On Linux, run
ip addr(or the short formip a) to list every interface with its IPv4 and IPv6 addresses. - Run
ip routeon Linux to see the default gateway on the line starting withdefault via. - Compare the address with the private ranges above to tell whether you are behind NAT.
- To see the public address your traffic leaves from, check your router status page.
C:\> ipconfig
Ethernet adapter Ethernet:
Link-local IPv6 Address . . . . . : fe80::1c2a:3b4c:5d6e:7f80%12
IPv4 Address. . . . . . . . . . . : 192.168.1.25
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP
link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.25/24 brd 192.168.1.255 scope global dynamic eth0
inet6 fe80::5054:ff:fe12:3456/64 scope link
$ ip route
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.25In the Linux output, dynamic on the inet line shows that the address was leased from DHCP, and scope link on the IPv6 line marks the link-local address. On Windows, the %12 after a link-local address is the zone index, which tells the system which interface the address belongs to.
More everyday Linux tools are covered in the Linux commands reference.
Practical exercise: map the addressing on your own network
Using only your own devices, record how your home or lab network is addressed.
- Find the IPv4 address, prefix length, default gateway and DNS servers on two devices, such as a laptop and a phone.
- Work out the network address and broadcast address for that prefix.
- Note whether each address is private, and whether it came from DHCP or was set statically.
- Find the link-local IPv6 address on the laptop and, if present, any global IPv6 address.
- Ping the gateway, then ping
127.0.0.1and::1, and record which replies arrive.
You are done when you have a small table listing each device, its addresses, the network and broadcast addresses, the gateway and the address source, and you can explain why both devices reach the internet through one public address. Addressing labs like this are part of the Networking Foundation course.
Common mistakes
- Assigning the network or broadcast address of a subnet to a device.
- Setting a static address inside the DHCP pool, which causes duplicate address conflicts.
- Using more than one
::when shortening an IPv6 address. - Treating NAT as a firewall and skipping proper filtering rules.
- Forgetting that
172.16.0.0/12runs up to172.31.255.255, not just172.16.x.x.
Frequently asked questions
What is the difference between an IP address and a MAC address?
A MAC address is a 48-bit hardware identifier used only on the local network segment. An IP address is a logical address used to route packets between networks. ARP links the two on IPv4 networks; the OSI model guide shows the layers each one belongs to.
Can two devices have the same IP address?
Not on the same network, because traffic would reach the wrong device. Devices on different private networks can share an address such as 192.168.1.10, because NAT keeps them apart on the internet.
Does every device need an IPv6 address now?
Every IPv6-enabled interface creates a link-local address automatically. Whether it also gets a global address depends on your ISP and router, so check the output of ip -6 addr or ipconfig.