How does HTTPS work? Walk through the TLS handshake at a high level.
Answer
HTTPS is HTTP sent over TLS (Transport Layer Security). TLS gives three guarantees: confidentiality (traffic is encrypted), integrity (tampering is detected) and authentication (the server proves it owns the domain via a certificate signed by a trusted Certificate Authority). During the handshake, the client and server use asymmetric cryptography to agree on a shared secret, then switch to fast symmetric encryption for the rest of the connection.
The TLS 1.3 handshake
TLS 1.3 (RFC 8446) completes the handshake in one round trip:
ClientHello: the client sends supported cipher suites, a random value, the server name via SNI (e.g. www.flipkart.com) and an ephemeral key share (ECDHE public key, usually X25519).
ServerHello: the server picks a cipher suite and sends its own key share. Both sides now compute the same shared secret with Diffie-Hellman, without ever sending it.
Encrypted server messages: everything from here is encrypted. The server sends its certificate chain, a CertificateVerify signature proving it holds the private key, and Finished.
Client verifies and finishes: the client checks the certificate and sends its own Finished. Application data (the HTTP request) flows.
TLS 1.2 needed two round trips and allowed static RSA key exchange; TLS 1.3 removed RSA key exchange and weak ciphers entirely. Resumed connections can use 0-RTT early data, but 0-RTT data can be replayed, so it should only carry idempotent requests.
How the certificate is trusted
The browser checks that:
The certificate's Subject Alternative Name matches the hostname.
It is within its validity period and not revoked.
It chains up through intermediates to a root CA in the OS or browser trust store.
The signature at each link is valid.
The server's private key never leaves the server. The certificate only contains the public key plus the CA's signature vouching for it. Let's Encrypt issues free domain-validated certificates via the ACME protocol, which is why HTTPS is now the default even for small projects.
Forward secrecy
Because TLS 1.3 always uses ephemeral Diffie-Hellman keys, recorded traffic cannot be decrypted later even if the server's long-term private key is stolen. This property is called forward secrecy, and it is why static RSA key exchange was removed.
What HTTPS does not protect
The domain name is visible through SNI and DNS unless Encrypted Client Hello (ECH) and encrypted DNS are used.
It does not make the server itself safe; a site with SQL injection is still vulnerable over HTTPS.
The first plain-HTTP visit can be downgraded; HSTS (Strict-Transport-Security) and the HSTS preload list fix that.
If a user clicks through a certificate warning, all guarantees are gone.
TLS 1.3 full handshake. One round trip agrees on keys and authenticates the server before any HTTP data is sent.
Server → Client: ServerHello: chosen cipher, key share
Server → Client: Certificate, CertificateVerify (encrypted)
Server → Client: Finished
Client → Server: Finished, then HTTP request
Server → Client: Encrypted HTTP response
Code examples
Inspecting a TLS connection
# Show negotiated protocol, cipher and certificate chain
openssl s_client -connect example.com:443 -servername example.com -tls1_3 </dev/null
# Just the certificate subject, issuer and validity dates
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null \
| openssl x509 -noout -subject -issuer -dates
# Verbose curl shows the handshake summary
curl -vI https://example.com 2>&1 | grep -E 'SSL connection|subject|issuer'
These commands let you see the TLS version, cipher suite and certificate chain a real server presents, which is useful when debugging certificate errors.
Key points
HTTPS = HTTP over TLS, providing confidentiality, integrity and server authentication.
TLS 1.3 completes a full handshake in one round trip using ephemeral ECDHE.
Asymmetric crypto agrees on keys and authenticates; symmetric crypto (AES-GCM, ChaCha20) encrypts data.
Certificates chain to a trusted root CA and must match the hostname.
Use HSTS to prevent downgrade to plain HTTP.
Common follow-up questions
What is forward secrecy and why did TLS 1.3 remove RSA key exchange?
What happens if a certificate is expired or the chain is incomplete?
What is mutual TLS and where is it used?
What is SNI, and what does Encrypted Client Hello hide?
Interview tips
Structure the answer as: goals of TLS, handshake steps, certificate validation. It sounds organised.
Say SSL is the deprecated predecessor; modern connections use TLS 1.2 or 1.3.
Explain why both asymmetric and symmetric crypto are used: one for key agreement, one for speed.