IP address and Subnet
Source: Dev.to
What does an IP address mean?
Every device that is connected to a computer network has a unique number called an IP address (Internet Protocol address). An IP address is like a home address: it tells the internet exactly where to send data, just as a postal address tells a delivery person where to drop off a package.
IP address versions
- IPv4 – the older and most common format. Written as four decimal octets separated by dots, e.g.,
192.168.1.1. It provides about 4.3 billion possible addresses (each octet ranges from 0 to 255). - IPv6 – the newer format created to solve IPv4 exhaustion. Written in hexadecimal groups separated by colons, e.g.,
2001:0db8:85a3:0000:0000:8a2e:0370:7334. It can handle an almost infinite number of addresses.
Public IP Address vs. Private IP Address
| Type | Assigned by | Usage | Scope |
|---|---|---|---|
| Public IP | Internet Service Provider (ISP) | Used on the internet | Globally unique |
| Private IP | Local network administrator | Used within a private network | Not directly reachable from the web |
Private IP ranges
10.0.0.0–10.255.255.255172.16.0.0–172.31.255.255192.168.0.0–192.168.255.255
The Parts of an IPv4 Address
An IPv4 address consists of 32 bits, grouped into four octets (8 bits each).
IP (decimal) : 192 . 168 . 1 . 10
IP (binary) : 11000000 . 10101000 . 00000001 . 00001010Each address has two logical parts:
- Network part – identifies the network the device belongs to.
- Host part – identifies the specific device on that network.
What is a Subnet?
A subnet (subnetwork) is a smaller division of a larger network. Instead of a single massive network with thousands of devices, the network is split into multiple, more manageable sub‑networks.
Subnet mask
A subnet mask is a 32‑bit number that indicates which portion of an IP address corresponds to the network and which portion corresponds to the host.
Example
- IP address:
192.168.1.10 - Subnet mask:
255.255.255.0
IP : 11000000.10101000.00000001.00001010
Mask : 11111111.11111111.11111111.00000000- The
1s in the mask represent the network part. - The
0s represent the host part.
In this example, the first three octets (192.168.1) identify the network, and the last octet (.10) identifies the host.
CIDR Notation
CIDR (Classless Inter‑Domain Routing) notation provides a compact way to express a subnet mask by counting the number of leading 1 bits.
| CIDR notation | Equivalent subnet mask |
|---|---|
192.168.1.0/24 | 255.255.255.0 |
10.0.0.0/8 | 255.0.0.0 |
172.16.0.0/16 | 255.255.0.0 |
Note: Two addresses in every subnet are reserved: one for the network address (the first address) and one for the broadcast address (the last address). Therefore, the number of usable hosts = total addresses − 2.
- Network Address – first address of a subnet (not assignable to a host).
- Broadcast Address – last address of a subnet (used to send data to all hosts in the subnet).