How the internet works? Good question. But before we try to answer that first let's try to figure out what the internet actually is.
The internet is a network of networks. Simple huh. So now you ask if I inter connect ten computers will it be called internet. The answer is yes and no. See when I say network of networks, I mean thousands and thousands of inter connected computer around the globe, not ten. Sure, you have an inter connected network of computers but its not the internet.
Now that we know it's a network of networks, how do all these computers communicate without ever breaking down? Let's try to understand how we human communicate. There are two things that are necessary in a communication, first another person and second the language. You both need to understand some common language, a standard of some kind which you both agree upon in order to converse or else it's going to fail.
Just like us humans, computers also have some standard upon which they agree to exchange information. A protocol of some kind. TCP/IP. These are two separate protocols but so similar that we usually say it in one breath.
Ok now we know that computers communicate through some kind of protocol. But how do they find each other between billions of other computers. Like we humans have home address which do not collide or at least are not supposed to collide, similarly computers also have some kind of addresses, Internet Protocol address (IP address) to be precise. An IP address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. In layman's term, IP address is how computers address each other.
We have the two necessary ingredients for communication. We have a way to uniquely identify the computer we wanna talk to. And we have a protocol which both the computers agree upon. Now we just need to make this information travel to the right destination, which is done by routers. Routers as you already guessed routes the information to the next right computer which in turn passes the information forward repeating the process till the final destination is reached.
Data is sent in many smaller packets as it is too inefficient to send it as a single file. Small packets of information sometimes travel through different routes, some of which take longer than the others. If you ever did two simultaneous speed tests and got different results, now you probably know why.
TCP/IP are two sets of convention that computers use to get data from one point to another. TCP also handles delivery, if any data gets lost or fails to reach the destination TCP sends a message to resend the data.
Now let's connect all the dots with an example. You want to go to Google, you type google.com in the address bar of your browser and you get the google page in return. Here's what happened behind the scenes, first the browser automatically converts your google.com to google.com.
HTTP is Hypertext Transfer Protocol, a protocol to transfer Hypertext Markup Language (HTML) document.
World Wide Web (www) is just a human convention. It is not necessary to write that in address bar.
google.com is the domain name which then gets converted to IP address of the web server (just another computer) where google is hosted. A human readable address like google.com is converted to IP address like https://172.217.3.196 with the help of DNS server. DNS servers translate human-memorable domain names (example.com) into the corresponding numeric Internet Protocol (IP) addresses (93.184.216.34)
HTTP has several request methods. GET and POST are two of them. GET literally means that get me this. When a computer requests for a website, this is generally how the request would look like.
GET / HTTP/1.1
HOST: google.com
- GET is the command.
- / means that you are requesting the home page of that website. Suppose you want google image search then you would pass /images instead of just / i.e google.com/images
- HTTP/1.1 is the version of HTTP protocol
- HOST says I want home page of only google.com, in case that particular web server is hosting multiple websites.
If the web server finds the requested page, it responds with
HTTP/1.1 200 OK
Content-Type: text/html
- HTTP/1.1 is the HTTP version
- 200 is the status code. 200 being for success.
- Content-Type: text/html is the type of content returned. In this case it is returning html file.
And this is how you get your google.com or facebook.com or any other site for that matter. All this is done in fraction of a second. Amazing isn't it.