Addresses: IP, MAC, ARP and IPv6
Lesson 4 of 4
4Addresses: IP, MAC, ARP and IPv6
The big pictureA postman needs the city to know where to send a letter, then the door number to hand it over. A network is the same: the IP address gets the packet to the right network, and the MAC address hands it to the right device inside.
What the picture shows: A MAC is a fixed card address; an IP is a logical network address. The first is for the hop, the second for the trip.
Map of this part
The concepts in order, click any one to jump to it:
Two ways into the same idea
A MAC address is like an ID number: born with the device and never changing. An IP address is like a home address: it changes when you move. At home the router gives you an "inside" address like 192.168.1.20, and millions of homes use the same one because it never leaves; to the outside the whole home shows one public address.
A MAC is 48 bits (6 hex bytes, the first three the maker's OUI) and works at layer 2. IPv4 is 32 bits in four octets, split into a network part and a host part by the prefix (/24). The private ranges in RFC 1918: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. ARP maps IP to MAC inside a network. IPv6 is 128 bits, has no broadcast, and shortens with ::.
Before You Start
🧅Layers
MAC lives at layer 2 and IP at layer 3.
🔢Binary
It helps to know 8 bits give numbers from 0 to 255.
The Core Idea
1Two addresses per device
You find the MAC under the router or in your phone settings, like 3C:22:FB:9A:10:7E. The first three bytes tell you the maker. The IP is in the same settings, and it changes when you move from the home network to the office.
2IPv4 in binary
A computer does not see 192.168.1.20; it sees 32 zeros and ones. Each of the four numbers is an "octet" of 8 bits, at most 255. Understanding binary is the key to subnets in the next part.
Change the address and see its bits.
address = "192.168.1.20"
octets = [int(part) for part in address.split(".")]
bits = [format(octet, "08b") for octet in octets]
print(" . ".join(bits))
print("as one number:", int("".join(bits), 2))3Private and public addresses
Some addresses are reserved for internal use and no internet router passes them. That is why your home and your neighbour's can both use 192.168.1.20 at once. The router translates them to the public address with NAT, which you meet in the routing part.
| Range | Prefix | Addresses | Where you see it |
|---|---|---|---|
10.0.0.0 – 10.255.255.255 | /8 | 16,777,216 | Large companies and the cloud |
172.16.0.0 – 172.31.255.255 | /12 | 1,048,576 | Medium networks and Docker containers |
192.168.0.0 – 192.168.255.255 | /16 | 65,536 | Homes and small offices |
127.0.0.1 | /8 | — | The machine itself (localhost) |
169.254.x.x | /16 | — | DHCP failed: the device gave itself one |
Notice 172.40.1.1 is public: the private range is only 172.16 to 172.31.
import ipaddress
for text in ["192.168.1.20", "10.4.0.9", "172.20.1.1", "172.40.1.1", "8.8.8.8", "169.254.3.7"]:
ip = ipaddress.ip_address(text)
kind = "private" if ip.is_private else "public"
if ip.is_link_local:
kind = "link-local (DHCP failed?)"
print(f"{text:<14} {kind}")4ARP: from IP to MAC
Your device knows the gateway's IP from its settings, but a frame needs a MAC. So it broadcasts a question to everyone: "who has 192.168.1.1?" Only the gateway answers with its address, and your device keeps it in the ARP table for a few minutes. Run arp -a in a terminal to see it.
5IPv6: addresses that do not run out
IPv4 gives only about 4.3 billion addresses, and they ran out years ago. IPv6 is 128 bits, written as eight hex groups, drops leading zeros and shortens the longest run of zero groups to :: once. It has no broadcast; multicast replaces it.
On 28 March 2026 the share of Google users on IPv6 passed half (50.1%) for a single day for the first time, then settled back to 45–48%. The practical point: you will run both versions side by side (dual stack) for years.
Python shortens and expands the address by the same rules.
import ipaddress
full = "2001:0db8:0000:0000:0000:ff00:0042:8329"
ip = ipaddress.ip_address(full)
print("short:", ip.compressed)
print("long: ", ip.exploded)
print("link-local fe80::1 ?", ipaddress.ip_address("fe80::1").is_link_local)Worked example
The task: ipconfig shows IPv4 192.168.1.37, mask 255.255.255.0, gateway 192.168.1.1. What do you know? The answer: the address is private (192.168), and the mask means /24, so devices .1 to .254 are on your local network. Any other address goes to the gateway .1, and your device only needs the gateway's MAC through ARP.
Myth vs Reality
| Myth | Reality |
|---|---|
| An IP address pins down exactly where you are. | It usually points to the provider and roughly the city, not the house. |
| A MAC address travels across the internet. | It stays in the local network; every router builds a new frame. |
| IPv6 is just a longer address. | It changes things: no broadcast, automatic address setup, and mostly no need for NAT. |
Where you meet it at work
🛠️IT support
169.254 or an address from another network points you straight at the problem.
🐳Developer
127.0.0.1 inside a Docker container is not your machine; each container has its own.
🔐Security
ARP poisoning is a classic attack where the attacker pretends to be the gateway.
Test your understanding
Which of these addresses is private (RFC 1918)?
The private 172.16.0.0/12 range runs from 172.16 to 172.31.
What does ARP do?
Names are DNS, handing out is DHCP. ARP joins layer 3 to layer 2.
How many bits in an IPv6 address?
IPv4 is 32 bits, MAC 48, IPv6 128.
Which is a correct short form of 2001:0db8:0000:0000:0000:0000:0000:0001?
:: only once, and only leading zeros in each group are dropped.
Which address is private under RFC 1918?
The private ranges: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.
How many bits are in an IPv6 address?
IPv4 has 32, MAC 48, IPv6 128.
Quick review cards
Check Your Understanding
Why can millions of homes use 192.168.1.20 at once?
Because it is private and never leaves; the router translates it to a unique public one.
Your device sends to a server on another continent. Whose MAC goes on the frame?
The gateway's, because it is the next hop.
Write 255 in binary.
11111111: eight ones.
Resources for this lesson
Grouped by type. Start with the official docs for precision, or an article or video for the explanation.
Done with this lesson?
Sign in to save your progress.