End-to-End Encryption in Chat Apps: Signal Protocol Basics
How end-to-end encrypted messaging works: identity keys, prekeys, X3DH key agreement, the Double Ratchet, forward secrecy, safety numbers and group sender ke...
Published November 27, 2026
End-to-end encryption (E2EE) means only the sender and recipients can read messages; the server relays ciphertext it cannot decrypt. WhatsApp, Signal and others use the Signal Protocol, which adds two important properties on top of basic encryption: forward secrecy (stealing today's keys does not reveal past messages) and post-compromise security (the conversation heals after a key compromise). This article explains the moving parts without the heavy math.
The concept
Every device has a long-term identity key pair and uploads a bundle of public prekeys to the server. To start a conversation with someone who may be offline, the sender downloads their prekey bundle and runs X3DH (Extended Triple Diffie-Hellman), combining several Diffie-Hellman exchanges into a shared secret that only the two devices can compute. The server stores and hands out public keys but never sees private keys or the resulting secret.
From that shared secret, the Double Ratchet derives a fresh key for every single message. A symmetric ratchet advances a chain key with each message, and a Diffie-Hellman ratchet mixes in new key material whenever the conversation changes direction. Old keys are deleted, which gives forward secrecy, and new DH exchanges mean an attacker who steals a key loses access again after a few messages.
Starting a session with X3DH
The Double Ratchet
- Shared root key from X3DH
- Each message: chain key → message key (symmetric ratchet)
- Reply with a new DH public key → new root and chain keys (DH ratchet)
- Delete used message keys immediately
- Compromise of one key exposes at most a few messages
Security properties
| Property | What it means | Provided by |
|---|---|---|
| Confidentiality | Server and network see only ciphertext | AEAD encryption with per-message keys |
| Authentication | You are talking to the holder of that identity key | Identity keys, safety numbers |
| Forward secrecy | Past messages safe if current keys leak | Deleting ratchet keys |
| Post-compromise security | Future messages become safe again | Fresh DH ratchet steps |
| Asynchronous start | Start chatting while recipient is offline | Prekeys and X3DH |
What the server still knows
E2EE protects message content, not metadata. The server still sees who talks to whom, when, how often, IP addresses, and approximate message sizes unless additional protections such as sealed sender or padding are used. Backups are another weak point: cloud backups of chat history must be encrypted with a key the provider does not hold, otherwise they bypass E2EE entirely.
Practical examples
Safety number verification
Users compare a fingerprint derived from both identity keys to detect a man-in-the-middle.
Safety number with Bob:
37281 90124 55609 13377 82041
66210 09431 77125 40986 21553
(scan QR code in person, or compare over a trusted channel)Conceptual message key derivation
Illustration of a symmetric ratchet step using HKDF; real implementations use libsignal.
import hmac, hashlib
def kdf_chain(chain_key: bytes) -> tuple[bytes, bytes]:
message_key = hmac.new(chain_key, b"\x01", hashlib.sha256).digest()
next_chain = hmac.new(chain_key, b"\x02", hashlib.sha256).digest()
return next_chain, message_key # delete chain_key after this stepUse a vetted library
Never implement the protocol yourself for production.
# Official implementation (Rust core with Java, Swift and TypeScript bindings)
https://github.com/signalapp/libsignalCommon mistakes
- Rolling your own cryptographic protocol instead of using libsignal or MLS implementations.
- Encrypting messages but uploading plaintext backups to the cloud.
- Putting decrypted message previews into push notification payloads.
- Ignoring identity key changes; clients should warn users when a contact's key changes.
- Assuming E2EE hides metadata such as who talks to whom.
Key takeaways
- The server distributes public prekeys but never sees private keys or plaintext.
- X3DH creates a shared secret even when the recipient is offline.
- The Double Ratchet gives a new key per message, forward secrecy and self-healing.
- Metadata, backups and push payloads need separate protection.
FAQ
How do group chats work with E2EE?
Signal-protocol apps use sender keys: each member shares a sender key with the group pairwise, then encrypts group messages once. The newer MLS standard (RFC 9420) is designed for efficient large-group E2EE.
Can a provider read messages if forced to?
Not past messages under correct E2EE. A provider could theoretically push a malicious app update or add a hidden device, which is why key-change warnings and transparency measures matter.
Does E2EE work across multiple devices?
Yes. Each device has its own identity keys, and senders encrypt for every device of every recipient.