If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Transport Layer Security (TLS)

Computers send packets of data around the Internet using the TCP/IP protocols. These packets are like letters in an envelope: an onlooker can easily read the data inside them. If that data is public information like a news article, that's not a big deal. But if that data is a password, credit card number, or confidential email, then it's risky to let just anyone see that data.
The Transport Layer Security (TLS) protocol adds a layer of security on top of the TCP/IP transport protocols. It takes advantage of both symmetric encryption and public key encryption for securely sending private data, and adds additional security features like authentication and message tampering detection. (Note that TLS was formerly known as SSL, so the two terms are often used interchangeably.)
TLS adds more steps on top of TCP/IP, so it increases latency in Internet communications. However, the security benefits are often worth the extra latency.

From start to finish

Let's step through the process of securely sending data with TLS from one computer to another. We'll call the sending computer the client and the receiving computer the server.

TCP handshake

Since TLS is built on top of TCP/IP, the client must first complete the 3-way TCP handshake with the server.
Diagram of two computers with arrows between. Computer on right is a server labeled with the IP address for khanacademy.org. A single arrow goes from laptop to server with a box above it that contains "ClientHello, ProtocolVersion: TLS 1.3, CipherSuites: TLS_RSA_WITH_RC4_128_SHA".
  • Arrow goes from laptop to server with "SYN" label.
  • Arrow goes from server to laptop with "ACK SYN" label.
  • Arrow goes from laptop to server with "ACK" label.

TLS initiation

The client must notify the server that it desires a TLS connection instead of the standard insecure connection, so it sends along a message describing which TLS protocol version and encryption techniques it'd like to use.
Diagram of two computers with arrows between. Computer on the left is a laptop showing a login screen for khanacademy.org. Computer on right is a server labeled with the IP address for khanacademy.org. A single arrow goes from laptop to server with a box above it that contains "ClientHello, ProtocolVersion: TLS 1.3, CipherSuites: TLS_RSA_WITH_RC4_128_SHA".

Server confirmation of protocol

If the server doesn't support the client's requested technologies, it will abort the connection. That may happen if a modern client is trying to communicate with an older server.
As long as the server does support the requested TLS protocol version and other options, it will respond with a confirmation, plus a digital certificate that contains its public key.
Diagram of two computers with arrows between. Computer on the left is a laptop showing a login screen for khanacademy.org. Computer on right is a server labeled with the IP address for khanacademy.org. A single arrow goes from server to laptop with box above that says "ServerHello, ProtocolVersion: TLS 1.3, CipherSuite: TLS_RSA_WITH_RC4_128_SHA, Certificate, ServerHelloDone".

Certificate verification

The server's digital certificate is the server's way of saying "Yes, I really am who you think I am". If the client doesn't believe the certificate is legit, it will abort the connection, since it doesn't want to send private data to an imposter.
Otherwise, if the client can verify the certificate, it continues on to the next step.
Client verification diagram. A laptop has a thought bubble coming out from it that says "Certificate = khanacademy.org?".

Shared key generation

The client now knows the public key of the server, so it can theoretically use public key encryption to encrypt data that the server can then decrypt with its corresponding private key.
However, public key encryption takes much more time than symmetric encryption due to the more difficult arithmetic operations involved. When possible, computers prefer to use symmetric encryption to save time.
Fortunately, they can! The computers can first use public key encryption to privately generate a shared key, and then they can use symmetric encryption with that key in future messages.
The client starts off that process by sending a message to the server with a pre-master key, encrypted with the server's public key. The client computes the shared key based on that pre-master key (as that is more secure than sending along the actual shared key) and remembers the shared key locally.
The client also sends a "Finished" message whose contents are encrypted with the shared key.
Diagram of two computers with arrows between. Computer on the left is a laptop showing a login screen for khanacademy.org. Computer on right is a server labeled with the IP address for khanacademy.org. A single arrow goes from laptop to server with box above that says "ClientKeyExchange (PreMasterSecret: c3ac534fd919a0e92b966795e), ChangeCipherSpec, Finished (21c124d28a548559f0f8abd4b)".

Server confirmation of shared key

The server can now compute the shared key based on the pre-master key, and attempt to decrypt the "Finished" message with that key. If it fails, it aborts the connection.
As long as the server can successfully decrypt the client's message with the shared key, it sends along a confirmation and its own "Finished" message with encrypted contents.
Diagram of two computers with arrows between. Computer on the left is a laptop showing a login screen for khanacademy.org. Computer on right is a server labeled with the IP address for khanacademy.org. A single arrow goes from server to laptop with box above that says "ChangeCipherSpec, Finished (c49fe482d338760807c3c278f)".

Step 3: Send secure data

Finally, the client securely sends the private data to the server, using symmetric encryption and the shared key.
Diagram of two computers with arrows between. Computer on the left is a laptop showing a login screen for khanacademy.org. Computer on right is a server labeled with the IP address for khanacademy.org. A single arrow goes from laptop to server with box above that has a string of encrypted data.
Oftentimes, the same client needs to send data to a server multiple times, like when a user fills out forms on multiple pages of a website. In that case, the computers can use an abbreviated process to establish the secure session.
Check your understanding
As you've seen, both computers must go through many steps to set up secure communication with TLS.
Complete the list of steps below:
  1. Client and server complete TCP handshake
  2. Client sends data encrypted with shared key

Certificate verification

In the TLS process above, the client does not send any data to the server until it has received and verified its digital certificate. That certificate verification step is a crucial part of what makes TLS so secure.
Why? Cybercriminals have many ways that they can intercept a request from one computer to another computer on the Internet, like DNS spoofing. A cybercriminal could route the TLS request to their own server instead, and respond with their server's public key.
Diagram of two computers with arrow between them. Computer on the left is a laptop showing a login screen for khanacademy.org. Computer on right is a server labeled with "khanacademy.org" in quotes. A single arrow goes from server to laptop with box above that says "Certificate PublicKey: b528971e78c9744f9ed1cc3c65". A cyber criminal is looking happily at the box. The server, arrow, and box are all colored red like the cyber criminal.
If the client does not properly verify the authenticity of the certificate, then it will complete the TLS handshake and send private data to the cybercriminal's server, which will happily decrypt the data.
Diagram of two computers with arrow between them. Computer on the left is a laptop showing a login screen for khanacademy.org. Computer on right is a server labeled with "khanacademy.org" in quotes. A single arrow goes from laptop to server with box above containing encrypted data. A cyber criminal is looking happily at the box. The server is colored red like the cyber criminal.
The client has shielded the rest of the Internet from seeing the data, but they delivered the secret straight into the enemy's hands!
Clients rely on certificate authorities to verify that a certificate (and its public key) belongs to a particular domain.
Any server that wants to communicate securely over TLS signs up with a certificate authority. The certificate authority verifies their ownership of the domain, signs the certificate with their own name and public key, and provides the signed certificate back to the server.
A made-up certificate that resembles certificates given to people that earn awards. The top says "Certificate of Authenticity". Under that, it says "This acknowledges that khanacademy.org is the proud owner of this public key:" and then has a long hexadecimal string. At the bottom, a line for the signature is labeled "Certificate Authority" and has the signature "GoDaddy Certificate Authority." Another line is labeled "Valid Dates" and has "10/13/2018 - 11/18/2020".
When the client inspects the certificate, it can see that a certificate authority is vouching for the authenticity of the public key. But it still has a decision to make: does it trust that certificate authority?
Clients generally come bundled with a list of trusted certificate authorities. For example, an Apple iPhone running iOS 10 trusts this long list of certificate authorities.
Apple users then have to trust Apple to continually monitor that list to make sure each certificate authority is verifying domains properly.
You can imagine a chain of trust from the user to the server:
An illustration of the certificate chain of trust. Starts with an icon labeled "user" on the left. There's an arrow labeled "trusts" from user icon to an icon of a smartphone labeled "client" . Another arrow labeled "trusts" flows from client icon to an icon of a computer labeled "certificate authority". A final arrow flows from certificate authority icon to an icon of a computer labeled "server".
At each point, trust can be broken. If the user doesn't trust the client, they can override the client's default list of trusted certificate authorities. If a client no longer trusts a certificate authority, it will remove it from the list. If a certificate authority sees suspicious behavior from a server, it can revoke its certificate.

TLS everywhere

TLS is used for many forms of secure communication on the Internet, like secure email sending and secure file upload. However, it's most well known for its use in secure website browsing (HTTPS), which we'll explore more in the next lesson.
TLS provides a secure layer on top of TCP/IP, thanks to its use of both public key and symmetric encryption, and is increasingly necessary to secure the private data flying across the Internet.

Want to join the conversation?