What is TLS?

In short
TLS, short for Transport Layer Security, is a protocol that protects data sent between two programs over a network. It is designed to prevent eavesdropping, tampering and message forgery. Version 1.3 is specified in RFC 8446, published by the IETF in 2018.
What TLS does
TLS is a protocol. A protocol is a set of rules that two programs follow when they talk to each other. TLS sits between an application protocol, such as HTTP, and the plain TCP connection underneath it. It wraps the data so that anyone watching the network sees only scrambled bytes.
The official specification describes TLS as a way for client and server applications to communicate over the Internet in a way designed to prevent eavesdropping, tampering, and message forgery. Those three goals are the heart of the protocol. Eavesdropping means reading data in transit. Tampering means changing it without anyone noticing. Message forgery means inventing messages that look genuine.
How it works
A TLS connection starts with a handshake. The client sends a first message, called a Client Hello, that lists the cryptographic options it supports. The server replies with a Server Hello that picks one of them. Both sides then exchange key material, so they can derive shared secret keys without sending those keys in the clear.
The server usually proves its identity with a certificate. The client checks that certificate against a list of trusted certificate authorities. If the check passes, the client knows it is talking to the right server and not an impostor in the middle. Once the handshake finishes, both sides encrypt every record they send. A record is one chunk of data wrapped in the protocol's framing.
Version 1.3 made the handshake shorter than in version 1.2. The specification says the design goal was to make the protocol faster to set up while keeping its security properties. It also removed several older algorithms that are no longer considered safe.
When to use it
Any time data travels across a network you do not fully control, you should protect it. Logins, payments, personal data and API calls all fall into this group. Most web traffic now uses HTTPS, which is HTTP running on top of TLS. Other protocols, such as email and database connections, can also run over TLS.
If you write a server, you usually do not implement TLS yourself. You rely on a well-tested library or on a web server that already includes it. Your job is to choose sensible settings, install a valid certificate and keep the software updated. Our reference on HTTPS is not a substitute for that, but the specification is the right place to check exact rules.
A simple example
From a developer's point of view, a TLS client usually looks like one function call that opens a secure connection. The library does the handshake and checks the certificate for you. For instance, in Python the standard library lets you wrap a socket like this:
import socket
import ssl
context = ssl.create_default_context()
with socket.create_connection(("example.com", 443)) as sock:
with context.wrap_socket(sock, server_hostname="example.com") as tls:
print(tls.version())
tls.sendall(b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n")
print(tls.recv(200))
The default context verifies the certificate and the host name. Turning that verification off makes the connection easy to attack, so avoid it outside of local testing.
Common mistakes
The first common mistake is disabling certificate checks to make an error go away. The connection then encrypts traffic, but it no longer proves who is on the other end. A second mistake is forcing old protocol versions. The specification notes that version 1.3 removed several older algorithms, so pinning an old version exposes your users to known weaknesses.
A third mistake is assuming that encryption alone is enough. TLS protects data in transit. It does not protect data stored on a disk, and it does not fix bugs in your application. Keep those concerns separate when you design a system.
Alternatives and related ideas
TLS is not the only way to protect network traffic. A virtual private network, or VPN, creates an encrypted tunnel for all traffic between two networks or devices. SSH provides a secure channel for remote login and file transfer. These tools solve related problems but work at different layers and for different use cases.
For web and API work, TLS is the default choice. Older names such as SSL are still used in everyday speech, but the protocols that carry that name are obsolete. When people say SSL certificate today, they usually mean a TLS certificate.
FAQ
Is TLS the same as SSL?
No. SSL was the predecessor of TLS and is now considered obsolete. People still say SSL out of habit, but modern connections use TLS.
Do I need to write TLS code myself?
Usually not. Use a well-tested library or a web server that includes TLS, and focus on configuring certificates and settings correctly.
What does TLS 1.3 change compared with TLS 1.2?
Version 1.3 has a shorter handshake and drops several older algorithms. The full list of differences is in the specification, RFC 8446.
Why does my client reject a certificate?
The certificate may be expired, issued for a different host name, or signed by an authority the client does not trust. Check each of these before turning verification off.
Sources
This page is based on the official documentation below. Read it for full detail.
TLS — official documentation ↗