How HTTP Works: Hypertext Transfer Protocol Explained

Everything you need to know about HTTP

Hypertext Transfer Protocol provides a network protocol standard that web browsers and servers use to communicate. You see HTTP every day because when you visit a website the protocol's written right in the URL (e.g. http://www.lifewire.com).

This protocol is similar to others like file transfer protocol in that it's used by a client program to request files from a remote server. In the case of HTTP, it's usually a web browser that requests HTML files from a web server, which are then displayed in the browser with text, images, hyperlinks, and related assets.

Because browsers by default communicate using HTTP, you can usually drop the protocol from a URL when you type it in the browser's address bar.

History of HTTP

Tim Berners-Lee created the initial HTTP standard in the early 1990s as part of his work in defining the original World Wide Web. Three primary versions were widely deployed during the 1990s:

  • HTTP 0.9: Support of basic hypertext documents
  • HTTP 1.0: Extensions to support rich websites
  • HTTP 1.1: Developed to address performance limitations of HTTP 1.0, specified in Internet RFC 2068

The latest version, HTTP 2.0, became an approved standard in 2015. It maintains backward compatibility with HTTP 1.1 but offers additional performance enhancements.

While standard HTTP does not encrypt traffic sent over a network, the HTTPS standard adds encryption to HTTP through the use of Secure Sockets Layer or, later, Transport Layer Security.

How HTTP Works

HTTP is an application layer protocol built on top of TCP that uses a client-server communication model. HTTP clients and servers communicate through request-and-response messages. The three main HTTP message types are GET, POST, and HEAD.

  • HTTP GET messages sent to a server contain only a URL. Zero or more optional data parameters may be appended to the end of the URL. The server processes the optional data portion of the URL, if present, and returns the result (a web page or element of a web page) to the browser.
  • HTTP POST — messages place any optional data parameters in the body of the request message rather than adding them to the end of the URL.
  • HTTP HEAD — requests work the same as GET requests. Instead of replying with the full contents of the URL, the server sends back only the header information (contained inside the HTML section).
Diagram of an HTTP GET message.

The browser initiates communication with an HTTP server by initiating a TCP connection to the server. Web browsing sessions use server port 80 by default, although other ports such as 8080 are sometimes used instead.

After a session is established, you trigger the sending and receiving of HTTP messages by visiting the web page.

HTTP is what's called a stateless system. What this means is that unlike other file transfer protocols such as FTP, the HTTP connection is dropped after the request has been completed. So, after your web browser sends the request and the server responds with the page, the connection is closed.

Troubleshooting HTTP

Messages transmitted over HTTP fail for several reasons:

  • User error
  • Malfunction of the web browser or web server
  • Errors in the creation of web pages
  • Temporary network glitches

When these failures occur, the protocol captures the cause of the failure and reports an error code back to the browser called an HTTP status line/code. Errors begin with a certain number to indicate what kind of error it is.

For example, errors with a failure code beginning with a four indicate that the request for the page cannot be completed properly or that the request contains incorrect syntax. As an example, 404 errors means that the page can not be found; some websites even offer fun custom 404 error pages.