>[!info] IP Address, IPv4 vs. IPv6
>An IP address is a unique identifier of a device in a network that uses the [[Internet Protocol Suite (TCP-IP)]] for communication.
>
>The two main versions are IPv4 (old), which uses a 32-Bit format like
>```bash
>192.168.0.1
>```
>and IPv6, which uses 128-Bit formats like
>```bash
>2001:0db8:85a3:0000:0000:8a2e:0370:7334
>```
The switch was made to make sure that there are enough addresses for all devices in the world.
Every IP address consists of **two parts**, a portion which identifies the network itself and the portion that identifies a specific host. This requires the specification of a subnet mask.
>[!info] Subnet Mask
>A subnet mask identifies the parts of the IP address that encode the network and the host (device) using binary maths.
```nginx
IP Address: 11000000.10101000.00000001.00001010 (192.168.1.10)
Subnet Mask: 11111111.11111111.11111111.00000000 (255.255.255.0)
```
In the above example you can see that 24 Bits are for the network, while 8 identify the device. Therefore, this subnet has $2^{8}=256$ IP addresses. An alternative notation is **CIDR**, which appends the number of network bits like `/24` to the IP.
```nginx
<IP Address>/<number of bits in the network portion>
```
In home networks, the older IPv4 is often in use (check via `ip a`), while the router has an IPv6 address (check via `curl ifconfig.me`). The translation is handled by [[NAT - Network Address Translation|NAT]] for IPv4, while IPv6 can work simply based on [[Packet Routing|routing rules]] and firewalls.
For IPv6, there is a shorthand notation via `::` that allows to omit zeros:
```bash
fd00::1 -> fd00:0000:0000:0000:0000:0000:0000:0001
```
>[!info] ULA - Unique Local Addresses
>Special reserved ranges that are never routed to the public internet (good for private networks).
|CIDR Block|Address Range|Typical Use|
|---|---|---|
|`10.0.0.0/8`|`10.0.0.0 – 10.255.255.255`|Large private networks|
|`172.16.0.0/12`|`172.16.0.0 – 172.31.255.255`|Corporate subnets|
|`192.168.0.0/16`|`192.168.0.0 – 192.168.255.255`|Home routers, Wi-Fi|
|Prefix|Example Address|Use Case|
|---|---|---|
|`fd00::/8`|`fd42:1337:cafe::1`|Internal VPNs, homelabs|
|`fc00::/7`|Reserved (not used in practice)|—|
>[!info] Default Gateway
>Network device (by IP) that your machine sends data to when communicating with the outside world, usually router.
>[!brainwaves] Analogies
>- Routers IP address is like a home address, local IPs like room numbers
>- DNS is address book
>- Subnet mask decodes street address vs room number
---