There is always a mystery about what happens in background when we do a simple task by typing google.com in address bar of browser. There are lot of things happening behind that address that we are not aware of , lets demystify this process and get a good understanding about this topic.
URL stands for Uniform Resource Locator which uniquely identifies each resource in the internet, URL consists of different parts including protocol, host name, port, query string etc.
This is a typical example of an URL , it consists of following
These are the steps carried by our browser and google server to establish connections and provide results to us
When we type google.com browser automatically adds https and www to the URL and prepares to send the request, but before sending request browser need to know the IP address of the server that it will be communicating with, because it cannot communicate directly with host name i.e. google.com
We can take understand better with this example that when we need to call someone from our phone we search for that person's name because names are easy to remember as compared to mobile numbers, same with web URLs , its easier to remember the website name as compared to IP addresses.
e.g. lets take an IPv4 172.23.45.76 and IPv6 2001:0000:3238:DFE1:0063:0000:0000:FEFB
As we can see its difficult to remember even one IP and we have to remember hundreds of IP to access websites we daily visit.
So browser makes a DNS request to DNS server and asks for the IP of the given hostname (website name) and gets the IP.
When we visit any website we see this padlock sign in address bar with label secure, so what is this label securing ?
This label shows that our connection to the server is secured and no one in the middle can intercept this connection and listen to it, but how does it really happen?
This happens after the process call SSL negotiation in which our browser verifies the server SSL certificate to check that the server is really that it claims to be. e.g. google.com will have a SSL certificate that is issued to google.com and unique to google.com so no one can pretend to be google.com
And after this negotiation a session key is created by our browser and google.com server and all the forgoing traffic is encrypted using this key.
After all this procedure our browser send the HTTP request to the server requesting the specific resource from server.
In HTTP request browser supplies with all the appropriate headers that are helpful to server to serve this request better.
So these are just the brief steps that are followed when we visit any website from our browser and there are many things we can go deep inside to learn more because no knowledge is enough.