# IP Addresses

> The unique digital coordinates assigned to every device connected to the internet.

Subject: Internet | Lesson 4 of 35 | 3 min read
Interactive lesson: https://codewithanimation.in/internet/ip-addresses
Previous: [TCP/IP Suite](https://codewithanimation.in/internet/tcp-ip-suite.md) | Next: [Domain Names](https://codewithanimation.in/internet/domain-names.md)

## What is an IP Address?

Just like every house needs a unique street address to receive physical mail, every device connected to the internet requires a unique **IP (Internet Protocol) Address** to receive digital packets.

An IP address is a numerical label assigned to your device (like `192.168.1.5` or `142.250.190.46`). When you request a webpage, your router attaches your IP address to the packet so the server knows exactly where to send the HTML back.

## Why Developers Need It

As a web developer, you constantly interact with IP addresses. During local development, you test your apps on **`127.0.0.1`** (localhost).

When deploying apps, you configure DNS records to point your domain name to the public IP address of your server. Additionally, APIs often use IP allowlisting to restrict access for security.

## IPv4 vs IPv6 & Localhost

The original system, **IPv4**, uses 32-bit numbers formatted as four blocks (e.g., `192.0.2.146`). Because the world ran out of these 4.3 billion addresses, we created **IPv6**, which uses 128-bit numbers with letters (e.g., `2001:0db8:85a3:0000:0000:8a2e:0370:7334`).

**Public vs Private:** Your home router gets one *Public IP* from your ISP, which the entire internet can see. However, the router assigns *Private IPs* (usually starting with `192.168...` or `10...`) to the devices inside your house. The outside world cannot see your private IP.

**Localhost (127.0.0.1):** This is a special 'loopback' IP address. It tells your computer, 'Don't send this packet out to the network; send it right back to me.' This is how you view `http://localhost:3000` while coding!

## Common mistake: The Local IP Mistake

A classic beginner mistake is trying to share a locally running project with a friend across the country by giving them your private IP (e.g., `http://192.168.1.5:3000`). This won't work because `192.168.1.5` only exists inside your own house's local network!

## Tip: Finding your IP

Open your terminal and run `ping google.com` to see Google's public IP address. To find your own public IP, you can literally Google 'what is my IP'.

## Try it: The Loopback vs Public Simulator

Try sending a packet to the loopback address (`127.0.0.1`), a private address (`192.168...`), and a public address to see how they route differently!

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/internet/ip-addresses

## Check yourself

### Question 1

Why was IPv6 created?

- A. To make the internet run faster by reducing packet sizes.
- B. Because we literally ran out of the 4.3 billion possible IPv4 addresses.
- C. To automatically encrypt all internet traffic.
- D. To prevent hackers from performing DDoS attacks.

Correct answer: B

IPv4's 32-bit system only allowed for about 4.3 billion unique addresses. With smartphones, smart TVs, and IoT devices, the world ran out, necessitating the switch to the massive 128-bit IPv6 system.

- Why not A: IPv6 addresses are actually much larger (128-bit vs 32-bit) and don't inherently increase speed.
- Why not C: Encryption is handled by TLS/HTTPS in higher layers, not by the IP format itself.
- Why not D: DDoS attacks happen on both IPv4 and IPv6 networks.

### Question 2

What happens when you send a request to 127.0.0.1?

- A. The request is routed to your internet service provider's main server.
- B. The packet is immediately dropped by the router.
- C. The request loops back directly to your own computer without ever touching an external network.
- D. It triggers a DNS lookup for the nearest public website.

Correct answer: C

127.0.0.1 is the universal 'loopback' address (also known as localhost). It's incredibly useful for testing code locally without needing an active internet connection.

- Why not A: Your ISP never sees this request; it doesn't even leave your computer.
- Why not B: The router never sees the packet; it loops back inside your own computer's operating system.
- Why not D: 127.0.0.1 is specifically hardcoded in every OS to map to 'localhost' (itself).

### Question 3

Why can't your friend across the country view the website you are hosting on http://192.168.1.10:3000?

- A. Because 192.168.x.x is a private IP block that only exists within your local home network.
- B. Because port 3000 is reserved exclusively for the military.
- C. Because React only allows connections from the same city.
- D. Because they need to use HTTPS instead of HTTP.

Correct answer: A

Private IPs (like 192.168.x.x or 10.x.x.x) are used internally by routers to manage home networks. The public internet has no idea how to route traffic to those internal addresses.

- Why not B: Port 3000 is a common, open development port. It is not restricted.
- Why not C: React has no concept of geography; this is purely a networking limitation.
- Why not D: Using HTTPS wouldn't solve the routing issue; the private IP is still completely unroutable from the outside world.

## Remember this

- An IP address is the unique numerical coordinate for a device.
- IPv4 is the old 32-bit format. IPv6 is the new 128-bit format.
- Localhost (127.0.0.1) loops back to your own machine.
- Private IPs (192.168.x.x) only work inside your own building.
