🌐 Network Layer: IPv4 & NAT

IPv4 Overview

The network layer (Layer 3) handles logical addressing and routing. IPv4 addresses are 32‑bit numbers, usually written in dotted‑decimal format (e.g., 192.168.1.10). The address is split into four 8‑bit groups (octets), so each group can range from 00000000 to 11111111 in binary, which corresponds to 0 to 255 in decimal. This is why every octet must be between 0 and 255 – an address like 384.785.854.412 is invalid because those numbers exceed 255 and cannot be represented in 8 bits.

IPv4 Address Structure

An IPv4 address consists of a network part and a host part. The division is defined by the subnet mask (e.g., /24 or 255.255.255.0).

Example: 192.168.1.34 with mask 255.255.255.0
Network = 192.168.1.0, Host = 0.0.0.34

Binary representation helps understand the split:

192.168.1.34  β†’ 11000000.10101000.00000001.00100010
Mask 255.255.255.0 β†’ 11111111.11111111.11111111.00000000
Network bits (first 24) = 11000000.10101000.00000001
Host bits (last 8)      = 00100010

Binary ↔ Decimal Conversion

Each octet is 8 bits. To convert, remember the value of each bit position (from most significant to least):

Bit position76543210
Value1286432168421

Example 1: Binary to Decimal

Convert binary 10101100 to decimal.

1   0   1   0   1   1   0   0
128 64  32  16  8   4   2   1
↓   ↓   ↓   ↓   ↓   ↓   ↓   ↓
128+0 +32 +0  +8  +4  +0  +0 = 172

Result: 10101100β‚‚ = 172₁₀

Example 2: Decimal to Binary (Subtraction Method)

Convert decimal 86 to binary. Start with the largest bit value (128) and work downwards:

86
Can 128 be subtracted? No  β†’ bit 7 = 0
Can 64 be subtracted?  Yes β†’ bit 6 = 1, remainder = 86 - 64 = 22
Can 32 be subtracted from 22? No  β†’ bit 5 = 0
Can 16 be subtracted from 22? Yes β†’ bit 4 = 1, remainder = 22 - 16 = 6
Can 8 be subtracted from 6?  No  β†’ bit 3 = 0
Can 4 be subtracted from 6?  Yes β†’ bit 2 = 1, remainder = 6 - 4 = 2
Can 2 be subtracted from 2?  Yes β†’ bit 1 = 1, remainder = 2 - 2 = 0
Can 1 be subtracted from 0?  No  β†’ bit 0 = 0

Reading the bits from position 7 down to 0 gives: 01010110 (often written without the leading zero as 1010110, but for 8 bits we keep the full byte).

Result: 86₁₀ = 01010110β‚‚

Using Spreadsheet Formulas

In Microsoft Excel or LibreOffice Calc, you can use built‑in functions for quick conversion:

These functions are especially handy when you need to convert many addresses or verify your manual calculations.

Address Types

Special IPv4 Addresses

Some addresses have special meanings and should not be used as normal host addresses:

NAT – Network Address Translation

NAT allows multiple devices on a private network to share a single public IP address. It modifies IP addresses in packets crossing the router.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ PC1 β”‚ β”‚ Router β”‚ β”‚ Internet β”‚ β”‚ 192.168.1.2β”œβ”€β”€β”€β”€β”€β”€β”€ 192.168.1.1 (LAN)β”œβ”€β”€β”€β”€β”€β”€β”€ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ 203.0.113.5 (WAN)β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ (with NAT) β”‚ β”‚ PC2 β”‚ β”‚ β”‚ β”‚ 192.168.1.3β”œβ”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

How it works: The router keeps a translation table mapping (private IP:port) to (public IP:port). When a response comes back, it forwards it to the correct internal device.

Private Address Ranges (RFC 1918)

These addresses are reserved for use inside private networks and are not routable on the public internet. They are the foundation of NAT.

NetworkCIDRAddress Range
10.0.0.0 – 10.255.255.25510.0.0.0/816,777,216 addresses
172.16.0.0 – 172.31.255.255172.16.0.0/121,048,576 addresses
192.168.0.0 – 192.168.255.255192.168.0.0/1665,536 addresses

Port Forwarding

If a device on the internet wants to reach a specific server inside your private network (e.g., a PACS server or a remote monitoring station), it must connect to your public IP address. The router then needs a rule – called port forwarding – that tells it: β€œwhen a packet arrives on this public port, forward it to this private IP and port.” Without port forwarding, the router does not know which internal device should receive the incoming traffic.

Manual vs. Automatic IP Assignment

IP addresses can be assigned in two ways:

Carrier‑Grade NAT (CG‑NAT)

Because public IPv4 addresses are scarce, Internet Service Providers often use CG‑NAT (also called NAT444). They assign you a private IP from the range 100.64.0.0/10 (100.64.0.0 – 100.127.255.255) and then translate that to a public IP at their own router. This means multiple customers share one public IP. For medical devices that need to be reachable from the outside (e.g., remote patient monitoring), CG‑NAT can be problematic – you may need a public IP or a VPN.

Implications for Medical Devices

Practical Tips for Medical Engineers