how internet works

1. You press “ www.google.com “ in the browser

2. Browser checks DNS (URL : IP) cache to find the IP address of “ www.google.com:

1) browser cache
2) OS cache
3) router cache
4) ISP cache

3. If not found, ISP’s DNS server initiates DNS query to search IP recursively from server to server

1) ISP's DNS server ask other DNS server
    - ISP : DNS recursor
    - other : name server
2) Use routing table to find the fastest way 
3) Reach correct DNS server, send IP address to browser

4. Browser builds TCP connection with server that matches IP address

TCP/IP three-way handshake:
    1) Ask server for connection: Client -----SYN------> Server
    2) Server has open ports:     Client <----SYN/ACK---- Server
    3) Client acknowledges:       Client ------ACK------> Server

5. Browser sends HTTP request to the server

It is time to start transferring data
    1) POST request for user authentication
    2) GET request asking for web page

6. Server handles request and sends back response

- Web server: Apache, ...
- Request handler program: PHP, Ruby, ASP.NET,...
- Response: JSON, XML, HTML
- Response Status:
    - 1xx: an informational message only
    - 2xx: success
    - 3xx: redirect the client to another URL
    - 4xx: error on the client
    - 5xx: error on the server

7. Browser displays HTML content, and you see “ www.google.com “ web page

1) Render bare bone HTML skeleton
2) GET CSS, JavaScript files, etc 

More information see : What happens when you type an URL in the browser and press ENTER