AES Encryption Step by Step: Rounds, S-Box and Key Schedule
AES, the Advanced Encryption Standard, turns a 16-byte block of plaintext into 16 bytes of ciphertext under a key of 16, 24 or 32 bytes. AES-128 does it in 10 rounds, and each round is four simple steps on a 4 by 4 grid of bytes called the state: substitute every byte, shift the rows, mix the columns and combine with a round key. This page builds each step from its definition in FIPS-197 and follows the standard's own example through every state.
Learning objectives
- Lay out the 16-byte state and say which byte is which row and column
- Carry out SubBytes, ShiftRows, MixColumns and AddRoundKey on a state
- Compute an S-box entry and a multiplication in GF(2^8)
- Expand a 128-bit key into 11 round keys
- Explain why 10 rounds, and what the last round leaves out
Prerequisites
- XOR and hexadecimal
- No cryptography background; every step is shown on real bytes
The state
The 16 input bytes fill the state column by column: bytes 0 to 3 are column 0, bytes 4 to 7 column 1, and so on, so byte s[r + 4c] sits in row r, column c. Every step below works on that grid.
SubBytes: the only non-linear step
SubBytes replaces each byte by its entry in a fixed table, the S-box. The table is not arbitrary: each entry is the byte's multiplicative inverse in the finite field GF(2^8), followed by a fixed affine transform. The inverse makes the step strongly non-linear, and the affine transform removes the fixed points the inverse alone would leave. Two entries to remember: S({00}) = {63} and S({53}) = {ED}.
ShiftRows
ShiftRows rotates row r of the state left by r bytes: row 0 stays, row 1 moves one place, row 2 two, row 3 three. After it, each column holds one byte from each of the four original columns.
MixColumns
MixColumns multiplies each column, as a polynomial over GF(2^8), by a fixed polynomial with coefficients {02}, {03}, {01}, {01}. Each output byte depends on all four input bytes of its column, so one changed byte changes the whole column. ShiftRows then spreads those columns across the state in the next round.
AddRoundKey and the key schedule
AddRoundKey XORs the state with the round key. It is the only step that uses the key; without it, everything else could be undone by anyone.
Key expansion stretches the 16-byte key into 44 four-byte words, four per round key. Each new word is the word four places back XORed with the previous word, and every fourth word first goes through a rotation, the S-box and a round constant, so no two round keys are simple shifts of each other.
Worked example: the FIPS-197 vector, round by round
FIPS-197 works one block through the whole cipher as its example: plaintext 3243f6a8885a308d313198a2e0370734 under key 2b7e151628aed2a6abf7158809cf4f3c. Here is the state after every step, with the round key each AddRoundKey uses.
| Round | Step | State after the step | Round key |
|---|---|---|---|
| 0 | input xor key | 193de3bea0f4e22b9ac68d2ae9f84808 | |
| 1 | SubBytes | d42711aee0bf98f1b8b45de51e415230 | |
| 1 | ShiftRows | d4bf5d30e0b452aeb84111f11e2798e5 | |
| 1 | MixColumns | 046681e5e0cb199a48f8d37a2806264c | |
| 1 | AddRoundKey | a49c7ff2689f352b6b5bea43026a5049 | a0fafe1788542cb123a339392a6c7605 |
| 2 | SubBytes | 49ded28945db96f17f39871a7702533b | |
| 2 | ShiftRows | 49db873b453953897f02d2f177de961a | |
| 2 | MixColumns | 584dcaf11b4b5aacdbe7caa81b6bb0e5 | |
| 2 | AddRoundKey | aa8f5f0361dde3ef82d24ad26832469a | f2c295f27a96b9435935807a7359f67f |
| 3 | SubBytes | ac73cf7befc111df13b5d6b545235ab8 | |
| 3 | ShiftRows | acc1d6b8efb55a7b1323cfdf457311b5 | |
| 3 | MixColumns | 75ec0993200b633353c0cf7cbb25d0dc | |
| 3 | AddRoundKey | 486c4eee671d9d0d4de3b138d65f58e7 | 3d80477d4716fe3e1e237e446d7a883b |
| 4 | SubBytes | 52502f2885a45ed7e311c807f6cf6a94 | |
| 4 | ShiftRows | 52a4c89485116a28e3cf2fd7f6505e07 | |
| 4 | MixColumns | 0fd6daa9603138bf6fc0106b5eb31301 | |
| 4 | AddRoundKey | e0927fe8c86363c0d9b1355085b8be01 | ef44a541a8525b7fb671253bdb0bad00 |
| 5 | SubBytes | e14fd29be8fbfbba35c89653976cae7c | |
| 5 | ShiftRows | e1fb967ce8c8ae9b356cd2ba974ffb53 | |
| 5 | MixColumns | 25d1a9adbd11d168b63a338e4c4cc0b0 | |
| 5 | AddRoundKey | f1006f55c1924cef7cc88b325db5d50c | d4d1c6f87c839d87caf2b8bc11f915bc |
| 6 | SubBytes | a163a8fc784f29df10e83d234cd503fe | |
| 6 | ShiftRows | a14f3dfe78e803fc10d5a8df4c632923 | |
| 6 | MixColumns | 4b868d6d2c4a8980339df4e837d218d8 | |
| 6 | AddRoundKey | 260e2e173d41b77de86472a9fdd28b25 | 6d88a37a110b3efddbf98641ca0093fd |
| 7 | SubBytes | f7ab31f02783a9ff9b4340d354b53d3f | |
| 7 | ShiftRows | f783403f27433df09bb531ff54aba9d3 | |
| 7 | MixColumns | 1415b5bf461615ec274656d7342ad843 | |
| 7 | AddRoundKey | 5a4142b11949dc1fa3e019657a8c040c | 4e54f70e5f5fc9f384a64fb24ea6dc4f |
| 8 | SubBytes | be832cc8d43b86c00ae1d44dda64f2fe | |
| 8 | ShiftRows | be3bd4fed4e1f2c80a642cc0da83864d | |
| 8 | MixColumns | 00512fd1b1c889ff54766dcdfa1b99ea | |
| 8 | AddRoundKey | ea835cf00445332d655d98ad8596b0c5 | ead27321b58dbad2312bf5607f8d292f |
| 9 | SubBytes | 87ec4a8cf26ec3d84d4c46959790e7a6 | |
| 9 | ShiftRows | 876e46a6f24ce78c4d904ad897ecc395 | |
| 9 | MixColumns | 473794ed40d4e4a5a3703aa64c9f42bc | |
| 9 | AddRoundKey | eb40f21e592e38848ba113e71bc342d2 | ac7766f319fadc2128d12941575c006e |
| 10 | SubBytes | e9098972cb31075f3d327d94af2e2cb5 | |
| 10 | ShiftRows | e9317db5cb322c723d2e895faf090794 | |
| 10 | AddRoundKey | 3925841d02dc09fbdc118597196a0b32 | d014f9a8c9ee2589e13f0cc8b6630ca6 |
The ciphertext 3925841d02dc09fbdc118597196a0b32 is the one the standard gives, and every intermediate state matches its worked example. The same steps also reproduce the standard's second AES-128 test vector, 69c4e0d86a7b0430d8cdb78070b4c55a, and running the inverse cipher backwards from the ciphertext returns the plaintext.
Common mistakes
- Filling the state row by row. FIPS-197 fills it column by column, and ShiftRows then moves the wrong bytes.
- Doing MixColumns in the last round. Round 10 leaves it out; with it, the result matches no reference.
- Multiplying in ordinary integer arithmetic. GF(2^8) multiplication is shift and XOR, reduced by the polynomial x^8 + x^4 + x^3 + x + 1.
- Using ECB mode, as this page does, for real data. It encrypts equal blocks to equal ciphertext; real systems use a mode such as GCM.
- Writing table lookups indexed by secret bytes in software that attackers can time. The side-channel posts show why.
Quick check
1. Which AES step is non-linear?
SubBytes. ShiftRows, MixColumns and AddRoundKey are all linear over GF(2).
2. How many round keys does AES-128 use, and why one more than the number of rounds?
11: key 0 is added before round 1, then one per round.
3. Row 2 of the state is 0a 0b 0c 0d. What is it after ShiftRows?
0c 0d 0a 0b: row 2 rotates left by two bytes.
Exercises
E1 (easy). Compute S({53}) from the definition.
The inverse of {53} in GF(2^8) is {CA}, because {53} x {CA} = {01}. The affine transform of {CA} is {ED}, which is S({53}).
E2 (easy). Compute {57} x {83} and {57} x {13} in GF(2^8).
Repeated doubling gives {57} x {02} = {AE} and {57} x {04} = {47} (the reduction kicks in). Adding the needed powers: {57} x {83} = {C1}, and {57} x {13} = {FE}.
E3 (medium). Encrypt the FIPS-197 AES-128 test vector, plaintext 00112233445566778899aabbccddeeff under key 000102030405060708090a0b0c0d0e0f, and give round 1.
Round 0 gives 00102030405060708090a0b0c0d0e0f0. Round 1 runs through SubBytes, ShiftRows and MixColumns to 89d810e8855ace682d1843d8cb128fe4 after its key. The ciphertext is 69c4e0d86a7b0430d8cdb78070b4c55a, which pycryptodome and openssl confirm.
E4 (hard). Flip one bit of the plaintext. How many of the 128 state bits differ after each round?
1 after round 0, 19 after round 1 (one S-box output changes several bits, and MixColumns spreads them over one column), and about 64 from round 2 on: half the bits, as for two unrelated blocks. Full diffusion takes two rounds; the other eight are margin against attacks.
Interview questions
- Q1. What does each AES step contribute? Answer: SubBytes non-linearity, ShiftRows and MixColumns diffusion across the state, and AddRoundKey the dependence on the key.
- Q2. How would you build AES in hardware for high throughput? Answer: unroll and pipeline the rounds, one round per stage, so a new block enters every clock; the S-boxes are the critical path.
- Q3. Why must the last round skip MixColumns? Answer: so that encryption and decryption have the same structure; a final MixColumns would add no security, since it is linear and could be undone without the key.
Summary
- AES-128: 16-byte blocks, a 16-byte key, 10 rounds on a 4 by 4 state filled column by column.
- Each round: SubBytes, ShiftRows, MixColumns and AddRoundKey; the last round skips MixColumns.
- The S-box is the GF(2^8) inverse followed by an affine transform.
- Key expansion makes 11 round keys from 44 words.
- One flipped input bit changes about half the state within two rounds.
Related
Last verified
Checked against NIST FIPS 197 and two independent AES implementations on 27 November 2026.