Skip to content

Beginner · How the web and backends work · topic 2 of 54 · 25 min

Clients, servers, IP addresses and URLs

Explanation

A client is the program that asks, like your browser or a phone app. A server is the computer that answers. Every server has a number called an IP address, and DNS turns easy names like irctc.co.in into that number. A URL tells the client which server, which port and which page to ask for.

Client and server

A client is any program that sends a request: Chrome on your laptop, the Swiggy app on your phone, or even another server. A server is the program (and the computer it runs on) that receives the request and sends back a response. This way of working is called the client-server model.

One server can answer thousands of clients at the same time. The client starts the talk; the server waits and answers. A server never knocks on your phone first in plain HTTP.

IP addresses and domain names

Every computer on the internet has an IP address (Internet Protocol address). It is a number like 142.250.183.14 (the older IPv4 style) or a longer one like 2404:6800:4009:80b::200e (the newer IPv6 style). Computers find each other using these numbers.

Numbers are hard for people to remember, so we use domain names like irctc.co.in or google.com. DNS (Domain Name System) is a big phone book of the internet that turns a domain name into an IP address.

Think of it like this: DNS is like the contacts list on your phone. You tap "Amma" and the phone dials 98xxxxxxxx for you. You type flipkart.com and DNS looks up the number of the Flipkart server for you.

Ports

One computer can run many server programs at once. A port is a number from 0 to 65535 that says which program should get the message. Web traffic uses port 80 for HTTP and port 443 for HTTPS. When you build a backend on your laptop, it often listens on port 3000 or 8080.

Think of it like this: If the IP address is the address of an apartment building, the port is the flat number. The postman needs both to deliver the letter to the right family.

The parts of a URL

PartIn https://shop.example.in:8080/products/42?colour=red#reviewsMeaning
Protocol (scheme)httpsThe rules to talk with: http or https
Domain (host)shop.example.inWhich server; DNS turns it into an IP address
Port8080Which program on that server (optional; 443 is the default for https)
Path/products/42Which thing on the server you want
Query?colour=redExtra options as name=value pairs, joined with &
Fragment#reviewsA spot inside the page; it is never sent to the server
javascript
const url = new URL('https://shop.example.in:8080/products/42?colour=red&size=m#reviews');

console.log(url.protocol); // 'https:'
console.log(url.hostname); // 'shop.example.in'
console.log(url.port);     // '8080'
console.log(url.pathname); // '/products/42'
console.log(url.search);   // '?colour=red&size=m'
console.log(url.hash);     // '#reviews'
console.log(url.searchParams.get('size')); // 'm'
The built-in URL class splits an address into its parts. searchParams.get reads one query value.
Tip: localhost is a special name that always means "this same computer" (IP 127.0.0.1). When you open http://localhost:3000, your browser is the client and your own laptop is the server.

HTTPS: the locked version of HTTP

HTTP sends messages as plain text. Anyone on the same Wi-Fi or network path could read them. HTTPS is HTTP inside an encrypted tunnel (called TLS), so only the client and the server can read the messages. The padlock in the browser bar means HTTPS is on. Every real website and API should use HTTPS.

Careful: Never send passwords, OTPs or tokens in the query part of a URL (like ?password=1234). URLs are saved in browser history and in server logs, even with HTTPS. Send secrets in the request body or a header instead.

Watch the lesson

Clients, servers, IP addresses and URLs · 1/6

Client asks Server answers

Every web request has two sides. The client asks, and the server answers.

Prefer a video by a teacher? Find free videos on “how the internet works dns ip address url explained for beginners” on YouTube ↗

In real life: Searching trains on IRCTC

You type irctc.co.in. Your phone asks DNS for the IP address of that name. It then opens a secure HTTPS connection to that IP on port 443. When you search for trains from Delhi to Jaipur, the app builds a URL with a path and a query, and the server reads those parts to know what you want.

javascript
const search = new URL('https://trains.example.in/search?from=NDLS&to=JP&date=2026-11-02');
console.log(search.hostname);                 // trains.example.in
console.log(search.pathname);                 // /search
console.log(search.searchParams.get('from')); // NDLS
console.log(search.searchParams.get('to'));   // JP
The server reads the from, to and date values out of the query.

Practice (0/3 done)

Task 1 · Code · Javascript

Write a function urlParts(address) that returns an object { protocol, host, path, query }. protocol is without the colon ("https"), host is the hostname without the port, path is the pathname, and query is the search part without the "?" ("" when there is none).

Task 2 · Code · Javascript

Write a function getQuery(address, name) that returns the value of the query parameter called name, or null when it is not in the URL. Encoded values like New%20Delhi must come back decoded ("New Delhi").

Task 3 · Code · Javascript

Write a function portOf(address) that returns the port as a number. If the URL has no port written, return the default: 443 for https and 80 for http.

Quick quiz

Question 1

1.What does DNS do?

Question 2

2.Which port does HTTPS use by default?

Question 3

3.In https://shop.in/cart?coupon=DIWALI, what is the path?

Question 4

4.Which part of a URL is never sent to the server?

Question 5

5.Why is HTTPS better than HTTP?

Read more (free)

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

← Previous: What is a backend?