Back to Blog
cryptography·

AES-256-CBC Explained: Padding, IV and Block Size

How AES-256-CBC works: the 16-byte block size, PKCS#7 padding, why the IV must be random, and how to encrypt data safely. Includes working code examples.

aesencryptioncryptographysymmetric-encryption

Frequently asked questions

What is the block size of AES?

AES always uses a 128-bit (16-byte) block size, regardless of whether the key is 128, 192 or 256 bits.

What padding does AES-CBC use?

AES-CBC needs plaintext to be a multiple of 16 bytes, so it is normally padded with PKCS#7: each padding byte holds the number of padding bytes added. Without authentication, CBC padding is vulnerable to padding oracle attacks.

Does AES-CBC need an IV, and does it have to be secret?

Yes. CBC needs a 16-byte IV that is unpredictable and unique for every encryption. It does not need to be secret and is usually stored alongside the ciphertext.

What is the difference between AES-256 and AES-256-CBC?

AES-256 is the cipher with a 256-bit key. CBC is the mode of operation that chains blocks together. AES-256-CBC means AES with a 256-bit key used in CBC mode.

Is AES-256-CBC secure?

The cipher is secure, but CBC provides no integrity protection. For new designs prefer AES-256-GCM, or add an HMAC to CBC (encrypt-then-MAC).

Try it yourself

Put these concepts into practice with the free online tool on DevGizmo.