# Domain Names

> Human-readable text strings that act as aliases for numerical IP addresses.

Subject: Internet | Lesson 5 of 35 | 3 min read
Interactive lesson: https://codewithanimation.in/internet/domain-names
Previous: [IP Addresses](https://codewithanimation.in/internet/ip-addresses.md) | Next: [DNS Resolution Process](https://codewithanimation.in/internet/dns-resolution-process.md)

## What is a Domain Name?

While computers require numerical IP addresses (like `142.250.190.46`) to locate each other, humans are terrible at memorizing random numbers.

A **Domain Name** (like `google.com`) is a human-readable alias that sits on top of an IP address. It acts as an easy-to-remember shortcut so you don't have to memorize strings of numbers.

## Why Developers Need It

Beyond just making websites accessible to humans, domain names dictate browser security.

Browsers enforce the **Same-Origin Policy** and **CORS** based on domains. A script running on `api.yoursite.com` cannot automatically access data on `app.yoursite.com` without explicit permission, because the browser treats different subdomains as completely separate origins.

## The Domain Hierarchy

Domain names are read from right to left, moving from the broadest category to the most specific.

**1. TLD (Top-Level Domain):** The furthest right section (e.g., `.com`, `.org`, `.dev`). These are managed by a global organization called ICANN.

**2. Second-Level Domain:** The main brand name you buy (e.g., `google` in `google.com`).

**3. Subdomain:** The prefix added to the left (e.g., `www`, `api`, `blog`). You can create infinite subdomains for free once you own the second-level domain.

## Common mistake: Domain vs URL

A common mistake is using the terms 'Domain Name' and 'URL' interchangeably. A Domain Name (e.g., `github.com`) is just one part of a URL (Uniform Resource Locator).

The URL `https://github.com/facebook/react` includes the protocol (`https://`), the domain name (`github.com`), and the path to a specific file or route (`/facebook/react`).

## Tip: The Root Dot

Technically, every domain ends with an invisible dot (e.g., `google.com.`) which represents the absolute root of the internet's hierarchy. Browsers just hide it to make things look cleaner!

## Try it: Domain Dissector

Tap the different parts of the URL below to dissect and understand the anatomical structure of a web address.

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

## Check yourself

### Question 1

What is the primary purpose of a Domain Name?

- A. To encrypt the connection between a client and a server.
- B. To provide a human-readable alias for a numerical IP address.
- C. To host the actual files and images for a website.
- D. To automatically generate secure passwords.

Correct answer: B

Computers route traffic using IP addresses, but humans use Domain Names because words are much easier to remember than strings of numbers.

- Why not A: Encryption is handled by TLS/HTTPS, not the domain name.
- Why not C: Hosting is done by servers; the domain name just points to that server.
- Why not D: Domain names have nothing to do with password generation.

### Question 2

In the address 'blog.yoursite.com', what does 'blog' represent?

- A. The Top-Level Domain (TLD).
- B. The Second-Level Domain.
- C. A Subdomain.
- D. The Protocol.

Correct answer: C

Reading from right to left: '.com' is the TLD, 'yoursite' is the Second-Level Domain, and 'blog' is a Subdomain you created to separate your blog from your main site.

- Why not A: The TLD here is '.com'.
- Why not B: The second-level domain here is 'yoursite'.
- Why not D: The protocol would be 'http://' or 'https://', which isn't shown here.

### Question 3

What is the difference between a Domain Name and a URL?

- A. They are exactly the same thing.
- B. A Domain Name points to a server, while a URL is the specific address of a resource, including the protocol, domain, and path.
- C. A URL is used for websites, while a Domain Name is only used for email.
- D. A URL contains numbers, while a Domain Name only contains letters.

Correct answer: B

The Domain Name (e.g., 'example.com') gets you to the building. The URL (e.g., 'https://example.com/login') gives you the exact instructions on how to get there (https) and which specific room you want (/login).

- Why not A: They are often used interchangeably in casual conversation, but technically they are different.
- Why not C: Domain Names are used in both URLs and email addresses.
- Why not D: Both can contain numbers and letters.

## Remember this

- Domain names are human-readable aliases for IP addresses.
- Domains are read from right to left, getting more specific (TLD -> Second-Level -> Subdomain).
- A Domain Name is just one component of a full URL.
