Find a course

Module 2: Addresses and NamesLesson 3 of 1012 min

IP Addresses

Learn how IP addresses identify devices, read IPv4 and IPv6 addresses, and see how home routers use private addresses and NAT to share one public address.

Step 1 of 12Learn

Every device needs an address

To deliver a letter, the post office needs an address. To deliver data, the internet needs one too. Every device connected to the internet uses an IP address, where IP stands for Internet Protocol, the core rule set for addressing and delivering data.

The most common format, IPv4, looks like four numbers separated by dots:

192.0.2.45

Each of the four numbers, called an octet, ranges from 0 to 255. Why 255? Because each octet is stored as 8 bits (eight 1s and 0s), and 8 bits can represent 28 = 256 different values: 0 through 255. Four octets make 32 bits in total.

So how many IPv4 addresses are possible? 232, which is about 4.3 billion. In the 1980s that seemed like plenty. Today, with billions of phones, laptops, smart TVs, game consoles, cameras and sensors, it's nowhere near enough. The organizations that hand out addresses ran out of fresh IPv4 blocks in the 2010s.

Two solutions keep things working: a newer, much larger address system called IPv6, and a clever trick your home router uses to let many devices share one address. You'll see both in this lesson.

Step 2 of 12Practice · Spot the mistake

Which two of these are not valid IPv4 addresses?

Step 3 of 12Compare

IPv4 vs IPv6

AspectIPv4IPv6
Example192.168.1.252001:db8::1
Size32 bits128 bits
How many addressesAbout 4.3 billionAbout 3.4 × 1038
Written asFour numbers 0–255 with dotsEight groups of hex digits with colons
StatusRan out; stretched with NATGrowing share of traffic

Step 4 of 12Learn

Bits and binary

Computers store everything in binary, where each digit (bit) is 0 or 1. Each position in a binary number is worth double the one to its right:

Position value1286432168421
Bits for 19211000000

So binary 11000000 means 128 + 64 = 192. And 11111111 is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255, the largest value an octet can hold.

The pattern of doubling explains how address space grows. Each extra bit doubles the number of possible addresses:

  • 8 bits: 256 values
  • 16 bits: 65,536 values
  • 32 bits (IPv4): about 4.3 billion addresses
  • 128 bits (IPv6): about 3.4 × 1038 addresses

That last number is so large that there are more IPv6 addresses than grains of sand on Earth by an enormous margin. IPv6 addresses are written as eight groups of hexadecimal digits separated by colons, like 2001:db8:85a3::8a2e:370:7334 (the double colon is shorthand for a run of zeros). IPv6 adoption has grown steadily, and a large share of traffic to major services now uses it, while IPv4 remains in wide use alongside it.

Step 5 of 12Try the calculator

Build an octet from bits

Set each bit to 0 or 1 and see the decimal value. The default is 11000000, the first octet of many home addresses.

Decimal value
192

Step 6 of 12Practice · Work it out

What decimal number does the binary octet 10100000 represent?

Step 7 of 12Practice · Work it out

How many different values can be stored in 8 bits?

Step 8 of 12Learn

Public, private and NAT

Look at your phone's Wi-Fi settings at home and you'll probably see an address starting with 192.168. or 10.. Your friend's phone at their home may have the exact same address. How can that work?

Those are private addresses, reserved for use inside local networks and never used on the public internet. The reserved ranges are 10.x.x.x, 172.16.x.x through 172.31.x.x, and 192.168.x.x.

Here's how a typical home network works:

  1. Your ISP gives your router one public IP address, visible to the rest of the internet.
  2. Your router hands out private addresses to every device in the house, usually automatically through a system called DHCP (Dynamic Host Configuration Protocol).
  3. When your laptop requests a webpage, the router replaces the laptop's private address with the public one and remembers which device asked. When the response comes back, it forwards the data to the right device.

This translation is called Network Address Translation (NAT). It lets a whole household, or even a whole school, share a single public IPv4 address, which is a big reason the internet didn't grind to a halt when IPv4 addresses ran out.

One more special address: 127.0.0.1, called localhost, always means "this device itself."

Step 9 of 12Practice · Diagram

NAT at work

Which address does the website see?

Tap the shape that answers the question, then press Check.

NAT at workProcess diagram: Phone 192.168.1.20 → Router swaps the address → Sent as 203.0.113.7 → Website replies → Router forwards to phone.Phone 192.168.1.20Router swaps theaddressSent as 203.0.113.7Website repliesRouter forwards tophone
Addresses are examples from reserved documentation and private ranges.
Phone 192.168.1.20

A private address, only meaningful inside your home.

Router swaps the address

It records the connection in a table and replaces the private source address with its public one.

Sent as 203.0.113.7

The single public address your ISP gave your router.

Website replies

The reply goes back to 203.0.113.7.

Router forwards to phone

Its table says which device started that connection.

Step 10 of 12Practice · Sort into groups

Is each IPv4 address private (for local networks) or public?

Tap an item, then tap its group (or drag it there).

Step 11 of 12Note

Step 12 of 12Practice · Choose one

What does Network Address Translation (NAT) on a home router do?