Zamil's CSE Directory

computer networking

How the Web Works (HTTP/HTTPS)

Learn how browsers and web servers communicate using HTTP and HTTPS to load websites on the internet.

#networking#http#https#web#internet
networking, http, https, web, internet guides

In previous chapters we explored how data moves across networks using packets, TCP/UDP, ports, and sockets.

Now we can finally answer a very practical question:

What actually happens when you open a website?

When you type a web address into your browser, a complex sequence of events begins. Your browser communicates with a remote server, requests information, and receives the content needed to display the page.

This communication is made possible by a protocol called HTTP.

In this chapter we will explore:

  • how browsers and servers communicate
  • what HTTP requests and responses look like
  • how web pages are transferred
  • why HTTPS is used for secure communication

The Client and the Server

The web follows a client–server model.

Two main components are involved:

  • Client – the application making the request (usually your web browser)
  • Server – the machine hosting the website

When you visit a website:

  1. your browser sends a request to the server
  2. the server processes the request
  3. the server sends a response back

A simplified interaction looks like this:

sequenceDiagram
  participant Browser
  participant WebServer

  Browser->>WebServer: Request webpage
  WebServer->>Browser: Send webpage

This request–response model forms the foundation of how the web operates.


What is HTTP?

HTTP (Hypertext Transfer Protocol) is the protocol used for communication between web clients and web servers.

HTTP defines how requests and responses should be structured, allowing different systems to understand each other.

When your browser loads a webpage, it sends an HTTP request to the server.

The server responds with an HTTP response containing the requested content.


HTTP Requests

An HTTP request asks the server for a specific resource.

A resource might be:

  • an HTML page
  • an image
  • a stylesheet
  • a JavaScript file
  • an API response

A simplified request might look like this:

GET /index.html HTTP/1.1
Host: example.com

This request means:

  • GET → retrieve data
  • /index.html → the requested resource
  • Host → the domain name of the server

The browser sends this request to the server using TCP, typically on port 80.


HTTP Methods

HTTP defines several types of requests called methods.

Common methods include:

MethodPurpose
GETRetrieve data
POSTSend data to the server
PUTUpdate existing data
DELETERemove data

For example:

  • loading a webpage usually uses GET
  • submitting a form often uses POST

These methods allow web applications to interact with servers in structured ways.


HTTP Responses

After receiving a request, the server sends back an HTTP response.

A simplified response might look like this:

HTTP/1.1 200 OK
Content-Type: text/html

Followed by the actual webpage content:

<html>
  <h1>Hello World</h1>
</html>

The response contains:

  • a status code
  • headers describing the response
  • the body containing the requested data

HTTP Status Codes

Status codes indicate the result of a request.

Common examples include:

CodeMeaning
200Request succeeded
404Resource not found
500Server error
301Resource moved

For example, when you see a 404 error page, it means the server could not find the requested resource.


Loading a Web Page

A single webpage usually requires many HTTP requests.

When you visit a website, the browser might request:

  • the HTML document
  • images
  • CSS files
  • JavaScript files
  • fonts

A simplified process might look like this:

sequenceDiagram
  participant Browser
  participant Server

  Browser->>Server: Request HTML page
  Server->>Browser: Send HTML

  Browser->>Server: Request CSS file
  Server->>Browser: Send CSS

  Browser->>Server: Request image
  Server->>Browser: Send image

Modern websites may involve dozens or even hundreds of requests before the page is fully loaded.


The Problem with HTTP

Original HTTP communication has an important limitation:

it is not encrypted.

This means that data traveling between the browser and server could potentially be:

  • intercepted
  • read
  • modified

For sensitive activities like:

  • logging into accounts
  • entering passwords
  • making payments

this is not acceptable.

This led to the development of HTTPS.


HTTPS: Secure Web Communication

HTTPS (Hypertext Transfer Protocol Secure) is the secure version of HTTP.

HTTPS protects communication using encryption.

Instead of sending data in plain text, the data is encrypted so that only the client and server can read it.

HTTPS typically uses port 443.


Encryption with TLS

HTTPS relies on a security protocol called TLS (Transport Layer Security).

TLS provides:

  • encryption of transmitted data
  • verification of server identity
  • protection against tampering

When you connect to an HTTPS website, the browser and server perform a TLS handshake before exchanging data.

This process establishes a secure encrypted connection.


Recognizing Secure Websites

Modern browsers indicate secure connections in the address bar.

You may see:

  • https:// at the beginning of the URL
  • a lock icon indicating encryption

These signals show that communication with the website is protected.

Today, most websites use HTTPS by default.


Key Ideas to Remember

Web communication relies on the HTTP protocol.

Important ideas include:

  • The web uses a client–server model.
  • Browsers send HTTP requests to web servers.
  • Servers respond with HTTP responses containing resources.
  • HTTP uses methods such as GET and POST.
  • Status codes indicate the result of a request.
  • Modern websites often require many requests to load fully.
  • HTTPS adds encryption using TLS to secure communication.

These mechanisms allow billions of users to access websites safely and efficiently.


What Comes Next

Now that we understand how web communication works, we can explore the network devices that direct traffic across networks.

When packets travel across the internet, they must pass through machines responsible for directing them toward their destination.

In the next chapter we will explore routers and NAT, and learn how home networks connect to the wider internet.