← Back to list

Understanding AES-256 Encryption and Decryption: A Detailed Guide for All Levels

Part 1: Technical Explanation (For the Curious Minds)

Subhash Pathak · 2025-06-06 18:46 · 0 claps · 4.0 min read
#encryption #aes256 #aes-encryption #symmetric-encryption #cryptography
Open on Medium ↗
Wiki topics: CRY · Crypto & Web3 🔒 · Cybersecurity

Understanding AES-256 Encryption and Decryption: A Detailed Guide for All Levels

Part 1: Technical Explanation (For the Curious Minds)

What is AES-256?

AES-256 stands for Advanced Encryption Standard with a 256-bit key size. It is a symmetric encryption algorithm, which means the same key is used for both encryption and decryption. (Note: 256-bit key = 32 Characters)

Why AES-256?

  • 256-bit key: Offers extremely high security.
  • Block cipher: Encrypts data in 128-bit (16-byte) blocks.
  • Used by: Governments, banks, cloud storage, and secure messaging apps.

Internal Mechanics

AES-256 operates on a 4x4 byte matrix called the state. It runs through 14 rounds of transformation. Each round involves:

  1. Key Expansion: Generates 15 different round keys from the original 256-bit key. Although AES-256 performs 14 rounds of encryption but it needs 15 round keys because one is used in the initial AddRoundKey step before the first round, and then one for each of the 14 rounds.
  2. Initial Round:
  • AddRoundKey
  1. Main Rounds (13 total):
  • SubBytes: Byte substitution using a non-linear S-box.
  • ShiftRows: Rows are cyclically shifted.
  • MixColumns: Each column is mixed using matrix multiplication.
  • AddRoundKey: XOR with round key.
  1. Final Round:
  • SubBytes
  • ShiftRows
  • AddRoundKey (no MixColumns)

The result is a ciphertext that looks like random gibberish unless decrypted with the correct key.

Eg:

Decryption

AES decryption applies the inverse of each operation in reverse order:

  • InvSubBytes
  • InvShiftRows
  • InvMixColumns
  • AddRoundKey

All done using the keys in reverse sequence.

Eg:

Part 2: AES-256 in Layman’s Terms (For Everyone Else)

The Story of a Secret Message

Let’s say you want to send your friend the message:

"HELLO123"

But you don’t want anyone else to read it. So you use AES-256, like locking it in an unbreakable digital safe.

Step-by-Step Encryption (Making the Message a Mystery)

Break It Down

Your message is written into a little 4x4 grid: (Note: 16 bits at a time. 16*16 = 256)

H  E  L  L
O  1  2  3
.  .  .  .
.  .  .  .

(We fill extra spaces with padding.)

14 Rounds of Crazy Transformations

Each round does the same 4 tricks, but with new twists each time.

  1. SubBytes — Replace Every Letter

Imagine each letter is replaced with a code name from a secret table. So like:

  • H ➝ X1
  • E ➝ A9
  • L ➝ Z0

It’s like a super-advanced substitution cipher. No pattern. No guesswork.

  1. ShiftRows — Shuffle Each Row

Now, we shift each row to the left:

  • Row 1 stays the same
  • Row 2 shifts 1 spot
  • Row 3 shifts 2 spots
  • Row 4 shifts 3 spots

It’s like everyone in line at a concert steps sideways — it mixes up the order.

3. MixColumns — Stir the Columns

Now each column is mixed like a smoothie.

It’s not just shuffling — it’s math magic to make sure if even one letter changes, the whole column changes. Like mixing colors: blue + red = purple. Change red to yellow, you get green instead.

🔑 4. AddRoundKey — Lock with a Key

Finally, we XOR the whole thing with a special key.

This is like using a secret padlock that only your friend knows how to unlock. Each round uses a different lock 🔐.

Repeat 14 Times

Now you do this 14 times, each round:

  • More replacements
  • More shifts
  • More mixing
  • A new lock

By the end, your “HELLO123” looks like:

9f7D$a3X@!l&2#z%

Step-by-Step Decryption (Getting the Message Back)

Now, your friend wants to read the message. They use the same key and go backwards:

  • AddRoundKey: Remove the lock.
  • InvMixColumns: Unmix the smoothie.
  • InvShiftRows: Slide rows back to original spots.
  • InvSubBytes: Decode the secret codes back into real letters.

Do this 14 times, and you get back:

HELLO123

Other AES Encryption and Modes of Operation

AES comes in three standard key sizes, which define the number of transformation rounds:

  • AES-128: 128-bit key, 10 rounds
  • AES-192: 192-bit key, 12 rounds
  • AES-256: 256-bit key, 14 rounds

All three use the same basic algorithm structure; the difference lies in the number of rounds and key size, with AES-256 being the most secure.

Modes of Operation

AES, being a block cipher, requires a mode of operation to handle longer messages and add variability. Here are the most commonly used modes:

  • ECB (Electronic Codebook): The simplest mode. Encrypts each block independently. Weak because identical plaintext blocks result in identical ciphertext.
  • CBC (Cipher Block Chaining): Adds security by chaining blocks together. Each block of plaintext is XORed with the previous ciphertext block before encryption. Requires an Initialization Vector (IV). Very secure when IV is random.
  • CFB (Cipher Feedback Mode): Converts AES into a stream cipher. Good for encrypting data byte-by-byte or in real-time.
  • OFB (Output Feedback Mode): Also turns AES into a stream cipher. More resistant to transmission errors.
  • CTR (Counter Mode): Uses a counter for each block. Very fast and allows parallel processing.
  • GCM (Galois/Counter Mode): Combines CTR mode with authentication. Highly secure and used in TLS (HTTPS), VPNs, etc.

Final Thought

AES-256 might sound complex, but in essence, it’s like running your message through an insanely hard-to-crack maze. With the key, your friend can walk back through the maze and read your message. Without the key, a hacker sees only noise.

Whether you’re a techie or just curious, AES-256 is your digital lock-and-key against the wild world of data snooping.


메타데이터
post_id
3bdac5816ab8
slug
understanding-aes-256-encryption-and-decryption-a-detailed-guide-for-all-levels-3bdac5816ab8
url
https://medium.com/@subhash_pathak/understanding-aes-256-encryption-and-decryption-a-detailed-guide-for-all-levels-3bdac5816ab8
canonical_url
https://medium.com/@subhash_pathak/understanding-aes-256-encryption-and-decryption-a-detailed-guide-for-all-levels-3bdac5816ab8
author_url
https://medium.com/@subhash_pathak
status
ok
fetched_at
2026-07-19 13:41:27