← All articles
technologyhow does encryption workencryption basicspublic key encryptionAugust 14, 202610 min read

How Does Encryption Work? A Beginner-Friendly Guide

By the BrainSnail editorial team. How these articles are written and checked, and how to tell us when one is wrong.

Encryption transforms readable data into an unreadable form using a mathematical method and a key, so someone without the right key should not be able to recover the original information easily. It is one of the basic tools used to protect data stored on devices and sent across networks.

Plaintext, keys and ciphertext

Readable information before encryption is often called plaintext. An encryption algorithm combines that plaintext with a key to produce ciphertext, which should look meaningless to someone who intercepts it. A decryption process uses the appropriate key to turn the ciphertext back into readable data. The security should depend on keeping the key protected, not on hiding how the algorithm itself works.

This key idea is central to how encryption works. Modern encryption algorithms are usually public and studied by specialists. If a system becomes unsafe simply because an attacker learns which algorithm is being used, it is fragile. Strong designs assume the method is known and make guessing or deriving the secret key computationally impractical.

Symmetric and public-key encryption

Symmetric encryption uses the same secret key, or closely related secret information, for encryption and decryption. It is efficient and useful for protecting large amounts of data, but the two sides need a safe way to share the key. If the key is exposed, an attacker may be able to read the protected information.

Public-key encryption uses a key pair. One key can be shared publicly, while the matching private key is kept secret. This makes it possible to establish secure communication without first sharing one secret key through an already secure channel. In practice, many secure systems combine public-key methods for setup with fast symmetric encryption for the main data. That combination is a practical answer to how encryption works on the modern internet.

Encryption should also be distinguished from hashing and encoding. Encoding changes data into another representation so systems can store or transmit it, but it is not meant to hide the content from an attacker. Hashing creates a fixed-size output that is designed to be difficult to reverse and is often used for integrity checks or password storage. Encryption is different because authorised users need a way to recover the original plaintext. Keeping these tools separate prevents a lot of technology vocabulary from blurring together.

What encryption does and does not protect

Encryption is powerful, but it solves a specific part of security:

  • •Encryption can protect the confidentiality of stored or transmitted data.
  • •Strong keys make brute-force guessing far more difficult.
  • •Authentication is still needed to confirm who you are communicating with.
  • •Keys must be stored and exchanged safely.
  • •Encrypted data can still be deleted, corrupted, or stolen even if it cannot be read.

Understanding how encryption works also means noticing its limits. If malware steals a key, a weak password unlocks a device, or a user is tricked into sending data to the wrong person, strong encryption may not help. Secure systems often combine encryption with authentication, access controls, software updates, and careful key management. Security comes from the whole chain rather than one mathematical tool.

From the Caesar cipher to modern key sizes

A classic way to see why keys matter is the Caesar cipher, which shifts every letter a fixed number of places along the alphabet. With only 25 useful shifts, an attacker can simply try them all. Even a fully scrambled alphabet, with vastly more possible keys, falls to frequency analysis: in English text some letters, such as E and T, appear far more often than others, and those patterns survive the substitution. Arab scholars described this technique more than a thousand years ago. A huge number of possible keys is necessary, but it is not enough on its own.

Modern ciphers are designed so that their output shows no such patterns, leaving guessing the key as the only realistic attack. Each extra bit of key length doubles the number of possibilities, so a 128 bit key allows two raised to the power of 128 combinations, a number so large that trying them all is beyond any conceivable computer. This is why security advice focuses on key length and on well tested public algorithms such as AES, not on inventing a clever secret method. Homemade ciphers tend to fail in ways their designers never anticipated.

Agreeing a secret in public

Public-key methods solve a puzzle that sounds impossible: how can two strangers agree a secret key while an eavesdropper hears everything they say? A common way to picture the 1976 Diffie-Hellman method uses paint. Both people start with the same public colour. Each secretly adds a private colour and sends the mixture to the other. Each then adds their own private colour to what they received. Both end up with the same final mixture, but an eavesdropper who saw only the exchanged mixtures cannot easily separate them to work it out. Real systems use mathematics that is easy to do but very hard to undo.

It also helps to know what is protected when. The padlock in your browser means your connection to that website is encrypted in transit, so others on the network cannot read it. It does not mean the website is honest, and the company running it can still read what you send. End-to-end encryption, used by some messaging apps, goes further: messages are encrypted on your device and only decrypted on the recipient's, so the service in the middle cannot read them. Asking who holds the keys tells you who can see your data.

How Enigma was broken without breaking the maths

The German Enigma machine of the Second World War scrambled each letter through a set of rotating wheels that stepped forward with every key press, giving an enormous number of possible settings. Trying them all by hand was hopeless. Yet it was broken, first by Polish mathematicians led by Marian Rejewski in the early 1930s, who shared their methods with Britain and France shortly before the war, and then on an industrial scale at Bletchley Park, where Alan Turing and Gordon Welchman designed electromechanical machines called bombes to test possible settings quickly.

The codebreakers succeeded largely by exploiting flaws in design and habit rather than by raw computing power. Enigma never encrypted a letter as itself, which let analysts rule out many guesses about where a known word sat in a message. Operators often sent predictable text, such as weather reports or standard phrases, giving the codebreakers likely fragments of plaintext, called cribs, to test against. Some chose lazy settings that could be guessed. The lesson still shapes modern security: a strong cipher can be undone by small structural weaknesses and by the routine behaviour of the people using it.

Public keys with small numbers

The RSA method, published in 1977 by Ron Rivest, Adi Shamir and Leonard Adleman, shows how a public key can work. Choose two primes, say 3 and 11, and multiply them to get 33, which becomes part of the public key. Pick a public exponent of 3 and keep a matching private exponent of 7, worked out from the two primes so that the exponents undo each other. To encrypt the message 4, raise it to the power 3, giving 64, and keep only the remainder after dividing by 33, which is 31. Anyone can do this using only the public numbers.

To decrypt, the key holder raises 31 to the power 7 and again takes the remainder after dividing by 33, which returns exactly 4. Working out the private exponent requires knowing the two original primes, and with 33 that is trivial. Real keys use a number hundreds of digits long, made from two huge primes chosen at random. Multiplying the primes takes a computer a fraction of a second, but no known method on ordinary computers can split the product back into its factors in any practical time. Large quantum computers could in principle do it, which is why replacement methods are already being standardised.

The takeaway

Encryption uses an algorithm and a key to convert plaintext into ciphertext that unauthorized readers should not be able to understand. Symmetric and public-key systems solve different practical problems and are often used together. Think of encryption as a strong lock on information, then remember that the key and the surrounding system must also be protected.

Practise this

Questions from Cybersecurity

Reading about something is not the same as being able to recall it. These are real questions from the Cybersecurity unit in our Technology track, answers and explanations included. The unit has 114 in total across 22 steps.

  • Fill the blankLevel 2

    1. The secret used to lock and unlock encrypted data is called a ____.

    • keycorrect
    • door
    • wall
    • screen

    A key is the secret needed to scramble and unscramble encrypted data.

  • Fill the blankLevel 1

    2. Software made on purpose to harm a computer is called ____.

    • malwarecorrect
    • hardware
    • freeware
    • firmware

    Malware is the general name for any harmful software.

  • Sort into groupsLevel 3

    3. Sort each action into Safe or Risky.

    Answer: Update your software = Safe; Use strong unique passwords = Safe; Click links from unknown senders = Risky; Share your password with a stranger = Risky

    Updating and using strong passwords are safe, while clicking unknown links or sharing passwords is risky.