Skip to content
MD-5

Choose which cookies we can use. You can change this at any time from “Cookie settings” at the bottom of every page.

What is symmetric encryption? How it works, with examples

How symmetric encryption works, the main block and stream ciphers, why modes and nonces matter, and the practices that keep a shared key from becoming a breach.

By Updated 5 min read

On this page

Symmetric encryption uses the same secret key to lock and unlock data. It protects almost everything you do online, from the HTTPS connection to this page to the disk in your laptop, because it’s fast enough to encrypt gigabytes per second. Its one hard problem is getting that shared key safely to the people who need it.

This guide covers how symmetric encryption works, the main algorithms, the details that trip up implementations, and the practices that keep it secure.

The basic idea

A symmetric cipher takes two inputs, a key and plaintext, and produces ciphertext that looks like random noise. The same key turns the ciphertext back into plaintext. Anyone with the key can do both; anyone without it can do neither.

Four terms come up constantly:

  • Plaintext: the readable input.
  • Ciphertext: the encrypted output.
  • Key: the secret, usually 128 or 256 random bits.
  • Nonce or IV: a value that must be unique for each message, so the same plaintext never encrypts the same way twice. It isn’t secret and travels alongside the ciphertext.

In 1949 Claude Shannon described the two properties a good cipher needs: confusion (the relationship between key and ciphertext is complex) and diffusion (changing one bit of input changes about half the bits of output). Every modern cipher is built to deliver both.

Block ciphers and stream ciphers

Block ciphers

A block cipher encrypts fixed-size chunks: 64 bits for older designs, 128 bits for modern ones.

Cipher Year Block Key Status
DES 1977 64 bits 56 bits Broken by brute force; withdrawn
3DES 1998 64 bits 112 or 168 bits Disallowed for encryption after 2023
Blowfish 1993 64 bits 32 to 448 bits Unbroken, but block too small for bulk data
AES 2001 128 bits 128, 192, 256 bits Current standard
Twofish 1998 128 bits 128, 192, 256 bits Unbroken; niche

Block size matters more than it looks. With a 64-bit block, repeats in the ciphertext become likely after about 32 GB under one key, and repeats leak information. The 2016 Sweet32 (opens in a new tab) attack used exactly this to recover secrets from 3DES and Blowfish connections. 128-bit blocks push the limit far beyond realistic volumes.

Stream ciphers

A stream cipher generates a keystream from the key and a nonce, and XORs it with the data, byte by byte.

  • RC4 was fast and everywhere (WEP Wi-Fi, early TLS) but has serious statistical biases. WEP was broken in 2001, and the IETF prohibited RC4 in TLS (opens in a new tab) in 2015.
  • ChaCha20, designed by Daniel Bernstein, is the modern choice. Paired with the Poly1305 authenticator (RFC 8439 (opens in a new tab)), it’s used in TLS 1.3, WireGuard and SSH, and is fast on phones and other devices without AES hardware.

Modes: the step beginners miss

A block cipher only knows how to encrypt one block. A mode of operation decides how to handle everything longer, and choosing badly undoes the cipher’s strength.

The classic mistake is ECB mode, which encrypts each block independently. Identical plaintext blocks give identical ciphertext blocks, so patterns in the data stay visible. The well-known demonstration is a bitmap of the Linux penguin encrypted with ECB: the penguin is still clearly recognizable.

Modern code should use an authenticated encryption mode, which both hides the data and detects tampering:

  • AES-GCM, the default in TLS 1.3 and most cloud services.
  • ChaCha20-Poly1305, the alternative where AES hardware isn’t available.

Older modes such as CBC and CTR provide confidentiality only. Without a separate MAC, an attacker can alter the data undetected and, in some cases, decrypt it. The AES guide covers how padding-oracle and nonce-reuse attacks work in practice.

Strengths

  • Speed. Modern CPUs encrypt AES in hardware at gigabytes per second per core, which is why full-disk encryption and universal HTTPS are practical.
  • Small keys. A 128-bit key has 2^128 (about 3.4 × 10^38) possible values, beyond any brute-force search.
  • Low overhead. It runs comfortably on smart cards, sensors and embedded devices.

Weaknesses

  • Key distribution. Both sides need the same key before they can talk, and it must travel safely.
  • Scaling. Every pair of people needs their own key: n people need n(n-1)/2 keys, so 100 people need 4,950.
  • No proof of authorship. Anyone with the shared key could have produced a message, so symmetric encryption alone can’t prove who sent it.

Public-key cryptography solves the first and third problems, which is why real systems combine both. See symmetric vs asymmetric encryption.

Where it’s used

  • HTTPS: after the handshake, every byte is protected with AES-GCM or ChaCha20-Poly1305.
  • Disk encryption: BitLocker, FileVault and LUKS use AES in XTS mode.
  • Wi-Fi: WPA2 and WPA3 use AES.
  • VPNs: WireGuard uses ChaCha20-Poly1305; IPsec and OpenVPN mostly use AES-GCM.
  • Messaging: the Signal Protocol encrypts each message with AES.

Practices that keep it secure

These follow the OWASP Cryptographic Storage Cheat Sheet (opens in a new tab) and NIST’s key management guidance (SP 800-57) (opens in a new tab):

  • Use authenticated encryption (AES-GCM or ChaCha20-Poly1305) through a maintained library such as libsodium, Google Tink, or your platform’s crypto API. Never implement a cipher or mode yourself.
  • Generate keys randomly with a cryptographically secure generator. A password is not a key; if you must start from one, derive the key with Argon2id or PBKDF2.
  • Never reuse a nonce with the same key. Let the library generate nonces.
  • Keep keys away from data: in a key-management service or HSM, never in source code, config files or container images.
  • Rotate keys on a schedule, and record which key encrypted each item so rotation is straightforward.

When encryption fails in real applications, these are the reasons: hardcoded keys, reused nonces and unauthenticated modes. Those are what a web application penetration test checks when an application encrypts data itself.

Sources

Published by

· Certified cybersecurity services

Articles are researched and written in-house and link to their primary sources (standards, advisories, papers and public datasets) so you can check every claim. Spotted an error? Email contact@md-5.com and we’ll correct it.