⇄ Network Security

How TLS Works: Encryption in Transit Explained

Transport Layer Security (TLS) is the cryptographic protocol that protects the majority of traffic on the internet, from web browsing over HTTPS to email delivery and API calls. Understanding how TLS works matters because it is the primary defense that keeps data confidential and unmodified as it crosses untrusted networks. This article explains the mechanics of the handshake, certificates, and the encryption that follows, so you can reason about what TLS does and does not guarantee.

What TLS Protects and Where It Sits

TLS operates between the transport layer, typically TCP, and the application layer. An application protocol such as HTTP runs unchanged on top of TLS; the combination is what we call HTTPS. Because TLS wraps the application data, it provides three properties:

  • Confidentiality so a network eavesdropper cannot read the data.
  • Integrity so tampering is detected through message authentication codes.
  • Authentication so the client verifies the server's identity, and optionally the server verifies the client, using certificates.

Crucially, TLS protects data in transit, not data at rest. Once bytes arrive and are decrypted, TLS has no further role. It also does not hide which server you connect to at the IP level, and the destination hostname may be visible during connection setup.

The TLS Handshake Step by Step

Before any application data flows, the two parties negotiate parameters and establish shared keys in a handshake. A streamlined handshake proceeds roughly as follows:

  1. ClientHello carries the TLS versions the client supports, a list of cipher suites, a random value, and extensions such as the Server Name Indication (SNI) that names the target host.
  2. ServerHello picks a mutually supported version and cipher suite, returns the server's own random value, and begins key exchange.
  3. Certificate and key share present the server's certificate chain and its ephemeral public key parameters.
  4. Verification happens when the client validates the certificate and computes shared keys.
  5. Finished messages confirm the handshake with an authentication code computed over the transcript, proving nothing was altered.

Key Exchange and Authentication

The heart of the handshake is an authenticated key exchange. Contemporary TLS uses ephemeral Diffie-Hellman, typically the elliptic-curve variant known as ECDHE. Each side contributes a fresh key share, and both derive the same shared secret without that secret ever traversing the wire. Because the key material is ephemeral, capturing the traffic and later stealing the server's private key does not reveal past sessions, a property called forward secrecy.

Authentication is separate from key exchange. The server signs handshake data with the private key corresponding to the public key in its certificate. Only the legitimate key holder can produce a valid signature, which binds the key exchange to the server's verified identity and defeats a man-in-the-middle attack.

Deriving Session Keys

From the shared secret and the exchanged random values, both sides run a key derivation function to produce symmetric keys. Separate keys are derived for each direction of traffic, so client-to-server and server-to-client data use distinct keys.

Certificates and the Chain of Trust

A TLS certificate binds a public key to a hostname and is signed by a Certificate Authority (CA). Clients ship with a trust store of root CA certificates, and validation walks the chain:

  • The server's leaf certificate is signed by an intermediate CA.
  • The intermediate is signed by a trusted root.
  • The client checks each signature, the validity period, the hostname match, and revocation status.

If any link fails, whether an untrusted signer, an expired certificate, or a name mismatch, the client aborts. This public key infrastructure is what lets a browser trust a server it has never contacted before. Certificate transparency logs and revocation mechanisms such as OCSP stapling further harden the ecosystem against mis-issued certificates.

Symmetric Encryption of Application Data

Public key operations are expensive, so TLS uses them only to establish keys. Bulk application data is protected with fast symmetric algorithms. Robust deployments favor authenticated encryption with associated data (AEAD) ciphers such as AES-GCM or ChaCha20-Poly1305, which encrypt and authenticate in a single operation. Each record carries an authentication tag; if a bit is flipped in transit, tag verification fails and the record is rejected.

You can inspect a server's negotiated protocol and cipher with a simple command:

openssl s_client -connect example.com:443 -servername example.com

How TLS 1.3 Streamlines the Protocol

TLS 1.3 refined the protocol by removing legacy, weak options. Its improvements include:

  • A one round-trip handshake that reduces connection latency.
  • Mandatory forward secrecy achieved by removing static RSA key exchange.
  • A pruned list of cipher suites that eliminates known-weak algorithms.
  • Encryption of more of the handshake itself, shrinking metadata exposure.

These changes make secure defaults the norm rather than something an administrator must carefully assemble. Properly deployed TLS underpins other defenses such as encrypted DNS and VPN tunnels.

Key Takeaways

  • TLS provides confidentiality, integrity, and authentication for data in transit, sitting between TCP and the application.
  • The handshake performs an authenticated ephemeral key exchange, giving forward secrecy so past traffic stays safe even if a key later leaks.
  • Certificates and the CA trust chain let clients verify server identity and prevent impersonation.
  • Bulk data uses fast AEAD symmetric ciphers that encrypt and authenticate every record.
  • TLS 1.3 removes weak options and enforces secure defaults with a faster handshake.
tlsencryptionhttpshandshakenetwork-security

Frequently asked questions

What is TLS and how does it work?

TLS (Transport Layer Security) is the cryptographic protocol that encrypts data in transit between clients and servers, and it is the S in HTTPS. It works by performing a handshake in which the two sides authenticate and agree on shared keys, then encrypting all following application data with fast symmetric ciphers. This gives confidentiality, integrity, and server authentication as traffic crosses untrusted networks.

What happens during a TLS handshake?

In a TLS handshake the client and server exchange supported versions and cipher suites, perform an authenticated key exchange, and derive shared symmetric session keys before any application data flows. The server proves its identity by presenting a certificate and signing handshake data with its private key. Finished messages then confirm that nothing in the negotiation was tampered with.

What is the difference between TLS and SSL?

SSL is the older, deprecated predecessor to TLS, and although the terms are often used interchangeably, secure connections use TLS. TLS 1.2 and TLS 1.3 are the versions considered secure, with TLS 1.3 being faster and removing legacy weak options. Servers should disable SSL entirely to avoid its known vulnerabilities.

What does a TLS certificate do?

A TLS certificate binds a public key to a hostname and is signed by a Certificate Authority that clients already trust. During the handshake the client validates the certificate chain, checking the signatures, validity period, hostname match, and revocation status. This lets a browser verify it is talking to the genuine server and not an impostor.

What is forward secrecy in TLS?

Forward secrecy is a property where each session uses fresh, ephemeral key material, so capturing encrypted traffic and later stealing the server's private key does not reveal past sessions. TLS achieves it through ephemeral Diffie-Hellman key exchange, typically the elliptic-curve variant known as ECDHE. TLS 1.3 makes forward secrecy mandatory by removing static key exchange.

Does TLS protect data at rest?

No, TLS protects data only while it is in transit between two endpoints; once bytes arrive and are decrypted, TLS has no further role. Protecting stored data requires separate encryption at rest. TLS also does not hide which server you connect to at the IP level, and the destination hostname may be visible during connection setup.

Try it hands-on

K0G is an open toolkit of browser-based security utilities — hashing, encoding, JWT, certificates, crypto and more, all running locally in your browser.

Explore the tools →