How HTTPS and TLS Really Work: A Practical Guide
You've seen the padlock icon and the https:// prefix a thousand times. But when a certificate error blocks your API call or a mixed-content warning breaks your page, do you really know what's happening under the hood? This guide walks through the mechanics of HTTPS and TLS—the handshake, certificates, and encryption—so you can diagnose problems and make informed security decisions.
What HTTPS Actually Is
HTTPS is HTTP layered on top of TLS (Transport Layer Security). TLS provides three guarantees:
- Confidentiality: Data is encrypted so eavesdroppers can't read it.
- Integrity: Data can't be modified in transit without detection.
- Authentication: You're talking to the server you intended to reach, not an impostor.
Without TLS, HTTP sends everything in plain text—passwords, cookies, API keys—visible to anyone on the network path.
The TLS Handshake: Step by Step
Before any HTTP data flows, the client and server perform a handshake to agree on encryption parameters and verify identities. Here's the simplified flow for TLS 1.3 (the current standard):
- Client Hello: The client sends supported TLS versions, cipher suites, and a random value.
- Server Hello: The server picks a cipher suite, sends its own random value, and provides its certificate chain.
- Key Exchange: Both sides use ephemeral Diffie-Hellman to derive a shared secret without transmitting it. This provides forward secrecy.
- Certificate Verification: The client checks the server's certificate against trusted CAs, expiration, and hostname match.
- Finished: Both sides send a MAC over the handshake transcript to confirm integrity. Encrypted HTTP then begins.
TLS 1.2 requires two round trips; TLS 1.3 reduces it to one, improving latency. Most modern browsers and servers support TLS 1.3.
Certificates: The Trust Anchor
A certificate binds a public key to a domain name and is signed by a Certificate Authority (CA). Browsers and operating systems ship with a store of trusted root CAs. When a server presents its certificate, the client verifies:
- The certificate is signed by a trusted CA (directly or via an intermediate).
- The domain name matches the certificate's Subject Alternative Name (SAN).
- The certificate is within its validity period.
- The certificate hasn't been revoked (via OCSP or CRL).
If any check fails, the browser shows a warning. For APIs, your HTTP client will throw an error—often UNABLE_TO_VERIFY_LEAF_SIGNATURE or SSL_ERROR_BAD_CERT_DOMAIN. Never disable verification in production; instead, fix the certificate chain.
Common Certificate Problems
| Error | Likely Cause | Fix |
|---|---|---|
| Expired certificate | Forgot to renew | Renew and automate with Let's Encrypt |
| Hostname mismatch | Cert doesn't include the domain | Reissue with correct SAN |
| Incomplete chain | Missing intermediate cert | Configure server to send full chain |
| Self-signed cert | Not issued by public CA | Use a trusted CA or add cert to trust store |
How Encryption Works After the Handshake
Once the handshake completes, both sides have derived symmetric session keys. All application data is encrypted with a fast symmetric cipher (like AES-GCM or ChaCha20-Poly1305). The public-key operations in the handshake are only used to establish those keys—they're too slow for bulk data.
Each TLS record includes a sequence number and MAC to prevent replay and tampering. TLS 1.3 encrypts more of the handshake itself, hiding certificate details from passive observers.
Debugging TLS in Practice
When something goes wrong, these tools help you see what's happening:
openssl s_client -connect example.com:443 -servername example.comshows the certificate chain and handshake details.- Browser developer tools → Security tab displays connection info and certificate status.
curl -v https://example.comprints handshake and certificate verification steps.- Online SSL checkers (like SSL Labs) grade your configuration and flag weaknesses.
# Inspect a server's certificate chain
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null
Look for the Verify return code line—0 means success. If it's non-zero, the chain is incomplete or untrusted.
Best Practices for Your Servers
- Enable TLS 1.2 and 1.3 only; disable older versions.
- Use strong cipher suites (AEAD ciphers like AES-GCM).
- Automate certificate renewal (e.g., Certbot with Let's Encrypt).
- Enable HSTS to force HTTPS and prevent downgrade attacks.
- Regularly scan your configuration with SSL Labs.
These steps reduce attack surface and ensure compatibility with modern clients.
FAQ
What's the difference between TLS and SSL?
SSL is the deprecated predecessor to TLS. People often say "SSL" colloquially, but modern systems use TLS (versions 1.2 and 1.3).
Does HTTPS slow down my site?
TLS adds a small handshake overhead (a few milliseconds), but with TLS 1.3 and session resumption, the impact is negligible. Encryption also enables HTTP/2, which improves performance.
Can I use a self-signed certificate for internal services?
Yes, but clients must explicitly trust it. For internal APIs, consider a private CA or add the certificate to your system's trust store rather than disabling verification.
Need to inspect or format data from your logs while debugging TLS issues? Try our JSON formatter to pretty-print API responses and error payloads.