HTTP uses TCP as its transport layer protocol because TCP provides reliable, ordered, and error-checked delivery of a byte stream, which HTTP needs to ensure that web pages, images, and other resources arrive complete and in the correct order. HTTP is an application-layer protocol that assumes a reliable transport; TCP supplies that reliability, while also offering connection-oriented communication and flow control that suit the request-response nature of the web.
Background: The Layered Network Model
Network communication is organized in layers. The application layer (where HTTP lives) defines how programs exchange messages. The transport layer (where TCP and UDP live) handles end-to-end data transfer between processes. The internet layer (IP) routes packets across networks, and the link layer moves frames over physical media.
HTTP was designed in the early 1990s when the web needed to transfer hypertext documents reliably over unreliable networks. The designers chose TCP because it was already widely implemented and provided the necessary guarantees. UDP, the other common transport protocol, offers no reliability, ordering, or congestion control, so it was unsuitable for early web browsing.
How TCP Supports HTTP
TCP provides several features that HTTP relies on:
- Reliable delivery: TCP uses acknowledgments and retransmissions to ensure every byte sent is received. If a packet is lost, TCP resends it. HTTP does not need to implement its own retry logic for lost data.
- Ordered data: TCP delivers bytes in the same order they were sent. HTTP responses can be large and span many packets; TCP reassembles them correctly.
- Error detection: TCP checksums detect corrupted packets, which are discarded and retransmitted. This protects HTTP messages from silent corruption.
- Connection-oriented: TCP establishes a connection via a three-way handshake before data transfer. HTTP/1.0 and HTTP/1.1 use this to manage request-response exchanges and keep-alive connections.
- Flow control: TCP prevents a fast sender from overwhelming a slow receiver by adjusting the window size. This helps HTTP handle clients with varying bandwidth.
- Congestion control: TCP adapts its sending rate to network conditions, reducing the risk of congestion collapse. HTTP benefits from this without implementing its own congestion control.
Because TCP provides a reliable byte stream, HTTP can treat the connection as a simple pipe: it writes a request and reads a response without worrying about packet loss, duplication, or reordering.
Why Not UDP for HTTP?
UDP is a connectionless, unreliable datagram protocol. It does not guarantee delivery, ordering, or integrity. If HTTP used UDP directly, every HTTP implementation would need to add reliability, ordering, and congestion control—essentially reimplementing TCP. That would duplicate effort and likely produce inconsistent results.
However, HTTP/3 does use UDP as its transport, but not raw UDP. HTTP/3 runs over QUIC, a protocol built on UDP that adds reliability, ordering, encryption, and congestion control. QUIC moves those functions from the transport layer into the application layer (or a sublayer) to enable faster connection setup and avoid head-of-line blocking. So even HTTP/3 does not use unreliable UDP; it uses a reliable protocol built on UDP.
Common Problems and Misconceptions
A common misconception is that TCP is inherently slow or outdated. TCP's reliability mechanisms add overhead, but they are essential for most web traffic. Another misconception is that HTTP/3 eliminates TCP entirely; it replaces TCP with QUIC, which provides similar reliability guarantees.
TCP also introduces head-of-line blocking: if one packet is lost, subsequent packets must wait until it is retransmitted, even if they belong to different HTTP requests. This is one reason HTTP/2 multiplexing over TCP can suffer under packet loss, and why QUIC was developed. But for most web browsing, TCP's reliability outweighs these issues.
Alternatives and Comparisons
Other transport protocols exist, but none are direct substitutes for TCP in classic HTTP:
- UDP: Unreliable, no ordering, no congestion control. Used for DNS, streaming, gaming, and as the basis for QUIC.
- SCTP: Provides reliable, message-oriented delivery with multi-streaming, but is not widely supported on the public internet.
- QUIC: A reliable, encrypted transport over UDP, used by HTTP/3. It offers multiplexing without TCP head-of-line blocking and faster handshakes.
HTTP/1.1 and HTTP/2 use TCP. HTTP/3 uses QUIC. The choice depends on the version of HTTP and the capabilities of clients and servers.
How HTTP and TCP Work Together in Practice
When a browser requests a web page, it typically follows these steps:
- The browser resolves the domain name to an IP address using DNS.
- It opens a TCP connection to the server's IP address on port 80 (HTTP) or port 443 (HTTPS). This involves a three-way handshake: SYN, SYN-ACK, ACK.
- For HTTPS, a TLS handshake occurs over the TCP connection to establish encryption.
- The browser sends an HTTP request (e.g., GET /index.html HTTP/1.1) over the TCP connection.
- The server processes the request and sends an HTTP response, which TCP segments, transmits, and ensures arrives reliably.
- The browser reads the response, renders the page, and may reuse the TCP connection for additional requests (keep-alive) or open new connections.
TCP's role is invisible to the user but critical: it turns the unreliable IP network into a dependable stream for HTTP messages.
Frequently Asked Questions
Does HTTP always use TCP?
No. HTTP/1.1 and HTTP/2 use TCP. HTTP/3 uses QUIC, which runs over UDP. However, QUIC itself provides reliability and ordering, so HTTP still relies on a reliable transport, just not TCP.
Why does HTTP need reliable delivery?
Web pages consist of text, images, scripts, and styles that must be complete and correct. A missing or corrupted byte could break rendering or execute incorrect code. TCP's reliability ensures the browser receives exactly what the server sent.
Can HTTP work over UDP?
Not directly in standard versions. HTTP/3 uses QUIC over UDP, but QUIC adds the reliability and security that raw UDP lacks. Using raw UDP would require HTTP to implement its own reliability mechanisms.
What is TCP head-of-line blocking?
In TCP, if a packet is lost, all later packets must wait until the lost one is retransmitted and received, even if they are independent. This can delay HTTP/2 multiplexed streams. QUIC avoids this by handling streams independently.
Is TCP slower than UDP?
TCP has more overhead due to handshakes, acknowledgments, and congestion control, so it can be slower in some conditions. But for reliable data transfer like web pages, the overhead is necessary and usually acceptable.
Why was TCP chosen for the web originally?
TCP was already standardized and widely available when HTTP was created. It provided the reliability and connection management that early web designers needed without building custom transport logic.