How the internet works: IP addresses, DNS, domains and URLs

Lesson 2 of 8 · Web basics

How does a browser get from the words svetprogramiranja.com to the right computer somewhere in the world? This lesson covers IP addresses, packets, DNS, domains and the parts of a URL – and what exactly happens from the moment you press Enter until the page is shown.

Before you start: required prior knowledge – introduction to the web.
How to learn: try every example in the browser or on the command line and do the exercises from the lesson. The examples are in HTML, JavaScript and Python; for most of them a browser is enough, and for the Python examples you need Python 3 installed.

IP addresses and packets

Every device on the internet has an IP address – a number by which it is found, like a home address. There are two versions:

VersionLooks likeHow many addresses
IPv4216.24.57.1 – four numbers from 0 to 255about 4.3 billion (too few for all devices)
IPv62001:db8:85a3::8a2e:370:7334 – hexadecimal notationpractically unlimited (2128)

Data does not travel in one piece; it is split into small packets. Every packet has the sender's and the receiver's address and can take a different path through the network (via routers); at the destination they are put back in order. The TCP protocol takes care of that, and IP takes care of addressing – together TCP/IP.

In a home network devices have local addresses (e.g. 192.168.1.50), and the router represents them to the internet with one public address. The address 127.0.0.1 (or the name localhost) always means your own computer.

DNS: the phone book of the internet

People remember names, computers remember numbers. DNS (Domain Name System) translates a domain name into an IP address:

svetprogramiranja.com  ──DNS──▶  216.24.57.1
  1. The browser first checks whether it has asked for the address recently (the cache).
  2. If not, it asks a DNS server (usually the internet provider's, or a public one such as 1.1.1.1 and 8.8.8.8).
  3. If the DNS server does not know the answer, it asks in turn: the root servers → the server for .com → the server responsible for svetprogramiranja.com.
  4. The answer (the IP address) is remembered for a while so that next time it is faster.

DNS also keeps other records: A (the site's IP address), CNAME (another name), MX (where the mail for the domain arrives), TXT (verifications and security settings).

Try it: on the command line (Windows: cmd) type nslookup svetprogramiranja.com – you will get the site's IP address. The ping command measures how long a packet takes to reach the server and come back, and tracert (Linux/Mac: traceroute) shows which routers the packet passes through.

Domain and hosting

TermWhat it isExample
domainthe name of a site, rented (usually for a year) from a registrysvetprogramiranja.com
top-level domain (TLD)the last part of the name.com, .rs, .uk, .org, .edu
subdomaina part in front of the main name, chosen by the domain ownerwww.svetprogramiranja.com, takprog.petlja.org
hostingthe server where the site's files and program "live"Render, Netlify, GitHub Pages, a school server

A domain and hosting are two separate things: the domain says what the site is called, and a DNS record connects that name with the server (hosting) where the site is.

The parts of a URL

https://www.example.com:443/lessons/loops?grade=7&page=2#tasks
└─┬─┘   └──────┬──────┘└┬─┘└─────┬─────┘└──────┬──────┘└─┬─┘
  │            │        │        │             │         │
protocol     domain    port     path       parameters  anchor
PartMeaning
httpsprotocol – how the communication works (https is encrypted http)
www.example.comdomain (the name of the server)
:443port – the server's "door"; the default for https is 443 and for http 80, so it is usually not written
/lessons/loopspath – which page or file on the server
?grade=7&page=2query parameters – extra data for the server, name=value pairs separated by &
#tasksanchor – the part of the page the browser scrolls to (it is not sent to the server)

An example from this site: /binarna_pretraga#program opens a lesson and scrolls to the "Program" section.

The whole path: from Enter to the page

StepWhat happensLesson
1the browser splits the URL into partsthis lesson
2DNS: domain name → IP addressthis lesson
3a TCP connection with the server (port 443)this lesson
4TLS: agreeing on encryption, checking the certificate (the padlock in the address bar)Security
5the HTTP request GET /pathThe HTTP protocol
6the server processes the request and returns a response with HTMLWeb server
7the browser reads the HTML and sends new requests for CSS, JS and imagesThe HTTP protocol
8drawing the page and running JavaScriptFrontend and backend
Common mistakes and tips
  • An IP address is the device's "number", a domain is its "name" – DNS connects them.
  • localhost and 127.0.0.1 are always your computer – you will need them when you run your own server.
  • The anchor (#…) stays in the browser, while the parameters (?…) go to the server.

Check your knowledge

Open the quiz

How the internet works

1. What is DNS for?




2. What does the address 127.0.0.1 mean?




3. In the address https://example.com/tasks?page=3#solution, what is "page=3"?




4. Which port is the default for HTTPS?