How the internet works: IP addresses, DNS, domains and URLs
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.
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:
| Version | Looks like | How many addresses |
|---|---|---|
| IPv4 | 216.24.57.1 – four numbers from 0 to 255 | about 4.3 billion (too few for all devices) |
| IPv6 | 2001:db8:85a3::8a2e:370:7334 – hexadecimal notation | practically 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
- The browser first checks whether it has asked for the address recently (the cache).
- 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).
- If the DNS server does not know the answer, it asks in turn: the root servers → the server for
.com→ the server responsible forsvetprogramiranja.com. - 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).
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
| Term | What it is | Example |
|---|---|---|
| domain | the name of a site, rented (usually for a year) from a registry | svetprogramiranja.com |
| top-level domain (TLD) | the last part of the name | .com, .rs, .uk, .org, .edu |
| subdomain | a part in front of the main name, chosen by the domain owner | www.svetprogramiranja.com, takprog.petlja.org |
| hosting | the 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
| Part | Meaning |
|---|---|
https | protocol – how the communication works (https is encrypted http) |
www.example.com | domain (the name of the server) |
:443 | port – the server's "door"; the default for https is 443 and for http 80, so it is usually not written |
/lessons/loops | path – which page or file on the server |
?grade=7&page=2 | query parameters – extra data for the server, name=value pairs separated by & |
#tasks | anchor – 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
| Step | What happens | Lesson |
|---|---|---|
| 1 | the browser splits the URL into parts | this lesson |
| 2 | DNS: domain name → IP address | this lesson |
| 3 | a TCP connection with the server (port 443) | this lesson |
| 4 | TLS: agreeing on encryption, checking the certificate (the padlock in the address bar) | Security |
| 5 | the HTTP request GET /path | The HTTP protocol |
| 6 | the server processes the request and returns a response with HTML | Web server |
| 7 | the browser reads the HTML and sends new requests for CSS, JS and images | The HTTP protocol |
| 8 | drawing the page and running JavaScript | Frontend and backend |
- An IP address is the device's "number", a domain is its "name" – DNS connects them.
localhostand127.0.0.1are 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?
