> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How TCP and HTTPS Work Together

> Explains how DNS, TCP, TLS, and HTTP interact to establish and secure an HTTPS connection and deliver web pages.

Many people understand that TCP establishes a connection and HTTP requests data, but the exact sequence and responsibilities of each layer can be confusing. This guide clarifies the end-to-end flow when you type `google.com` in your browser, showing where DNS, TCP, TLS, and HTTP each fit.

You type `google.com` (browsers default to HTTPS if you don't include a scheme). HTTPS typically uses port `443`.

First, the browser needs an IP address for `google.com`. It checks its cache; if not found, it performs a DNS lookup to resolve the hostname to an IP address.

DNS queries are commonly sent over UDP, but they can fall back to TCP when responses are large or when the DNS server requires it. See [Demystifying DNS](https://learn.kodekloud.com/user/courses/demystifying-dns) for details.

## Step 1 — TCP connection: three-way handshake

Once the IP address is known, the browser establishes a transport connection to the server using TCP. TCP creates a reliable byte-stream channel via the three-way handshake:

* Client sends SYN
* Server responds with SYN-ACK
* Client responds with ACK

When the ACK is received, the TCP connection is ESTABLISHED.

![A dark-themed infographic titled "Three-Way Handshake" showing a client browser (https://google.com) on the left and a Google server on the right with blue arrows for SYN, SYN‑ACK, and ACK messages and "ESTABLISHED" labels. A horizontal connection bar at the bottom represents the established TCP connection.](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Networking/How-TCP-and-HTTPS-Work-Together/three-way-handshake-google-tcp.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=044020f3c91797a6894f8e0fcb36b60d)

What TCP provides:

* Reliable delivery (retransmit lost packets)
* Ordered byte-stream (sequence numbers and reassembly)
* Flow control and congestion control

What TCP does not provide:

* Encryption or message confidentiality

## Step 2 — TLS handshake (over TCP)

To secure HTTP traffic, the browser and server perform a TLS handshake over the established TCP connection. During this handshake:

* The client sends a ClientHello (supported TLS versions, cipher suites, key-exchange parameters).
* The server replies with a ServerHello and its certificate (plus any server key-exchange information).
* The client validates the certificate (is it valid for `google.com`, issued by a trusted CA?).
* Client and server derive shared symmetric keys from the exchanged parameters (keys are never sent in plain text).

These negotiated keys and parameters are then used to encrypt and authenticate HTTP messages. TLS handshake messages themselves are sent as TCP payloads.

Newer transport protocols such as QUIC integrate TLS 1.3 and run over UDP. QUIC is used by HTTP/3, so TLS is not strictly tied to TCP in all cases — TLS 1.3 can be part of QUIC's handshake instead. See HTTP/3 and QUIC for more information.

![A stylized infographic showing a browser connecting to google.com and a TLS handshake with arrows between the client and Google servers. It ends with an encrypted TCP tunnel depicted by a blue line and a padlock.](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Networking/How-TCP-and-HTTPS-Work-Together/google-tls-handshake-encrypted-tunnel.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=eba76dafe4b161da3ba0256e65816939)

## Step 3 — Encrypted HTTP over TLS, transported by TCP and routed by IP

After the TLS handshake completes, the browser encrypts the HTTP request using the negotiated session keys. Those encrypted bytes are then passed to TCP, which segments and sequences them for IP routing.

Example of the HTTP request that will be encrypted and sent:

```http theme={null}
GET / HTTP/1.1
Host: google.com
```

Flow on the server side:

* IP delivers packets to the server machine.
* TCP reassembles the encrypted byte-stream and handles retransmission if needed.
* TLS decrypts and verifies the data.
* The HTTP server receives the original HTTP request payload and prepares a response.

![A dark-themed infographic showing the flow of an HTTP GET request from a browser to a server, with layered labels for HTTP, TLS, TCP, and IP and visuals of locks, keys, and network nodes. The top illustrates a browser address bar (https://google.com) on the left and a server icon with the Google logo on the right.](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Networking/How-TCP-and-HTTPS-Work-Together/https-get-flow-tls-tcp-ip.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=e48d16b53c47fed45b9d1fc7f53d0228)

## Step 4 — Response: encrypted, transported, and rendered

The server builds the HTTP response (HTML and other assets). That response is encrypted by TLS, handed to TCP for segmentation and ordering, and sent back over IP to the client. When it arrives:

* TCP reassembles the encrypted stream in order.
* TLS decrypts and verifies integrity.
* The browser parses the HTTP response and renders the page.

![A dark-themed infographic showing an HTTPS request/response between a browser (left) and a Google server (right). It highlights layered network components labeled HTTP, TLS (with a lock and keys), TCP and IP, plus Internet routing in the middle.](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Networking/How-TCP-and-HTTPS-Work-Together/https-browser-google-tls-tcp-ip.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=91a98058183045a43481fdb193b7badd)

## Responsibilities by layer

| Layer | Primary responsibility | Example / notes |
| - | - | - |
| IP | Packet routing across networks | Routes packets toward the destination IP |
| TCP | Reliable, ordered, congestion-aware byte-stream | Three-way handshake; retransmission; flow control |
| TLS | Authentication, confidentiality, integrity | Certificate validation; encrypts HTTP payloads |
| HTTP | Application-layer requests/responses | `GET /`, `Host: google.com` |

## Summary — typical sequence for a new HTTPS connection

1. DNS resolves the hostname (`google.com`) to an IP address.
2. TCP performs a three-way handshake to create a reliable connection.
3. TLS handshake runs over that TCP connection to negotiate encryption keys and verify identity.
4. HTTP requests/responses are exchanged: encrypted by TLS, transported by TCP, and routed by IP.

Resources and further reading:

* [Kubernetes Documentation](https://kubernetes.io/docs/)
* [Demystifying DNS](https://learn.kodekloud.com/user/courses/demystifying-dns)
* [QUIC (HTTP/3) overview](https://en.wikipedia.org/wiki/QUIC)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/devops-interview-prep/module/c1eb3967-23d3-4a34-b23d-14a892f95e1d/lesson/0280ff5e-b7de-4f42-9127-9c44c44f01fa)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.