Data Security Insights

ECB vs. CBC: Differences Between These Block Cipher Modes

ECB exposes plaintext patterns, while CBC hides repeated blocks but does not authenticate ciphertext. Learn why modern systems should prefer an authenticated encryption mode.

Reviewed August 1, 2026
ECB vs. CBC: Differences Between These Block Cipher Modes featured image

Short answer: Do not use ECB to protect secret data. CBC prevents the obvious pattern leakage associated with ECB, but CBC provides confidentiality only and requires separate authentication plus careful IV and padding handling. For new general-purpose designs, prefer an authenticated encryption mode such as GCM or CCM when the platform supports it.

ECB vs CBC at a glance

PropertyECBCBC
Repeated plaintext blocksProduce repeated ciphertext blocksDo not produce the same ciphertext when chaining and IV handling are correct
Initialization vectorNot usedRequired and unpredictable for encryption
ConfidentialityLeaks structural patternsProvides confidentiality when implemented correctly
Integrity and authenticityNot providedNot provided
Recommended for new secret-data encryptionNoOnly when authenticated encryption is unavailable and a secure authentication construction is added

What is a block cipher mode of operation?

A block cipher such as AES transforms a fixed-size block. AES uses 128-bit blocks regardless of whether its key is 128, 192, or 256 bits. Real messages are usually longer than one block, so a mode of operation defines how the cipher processes a sequence of blocks.

The mode affects more than formatting. It determines whether repeated data exposes patterns, whether encryption can be parallelized, what IV or nonce rules apply, and whether the recipient can detect modification.

How ECB mode works

Electronic Codebook mode encrypts every plaintext block independently with the same key. The design is simple and parallelizable, but it has a critical consequence: identical plaintext blocks encrypted under the same key produce identical ciphertext blocks.

Diagram showing each plaintext block encrypted independently in ECB mode
ECB processes each block independently.

The well-known encrypted image example makes the problem visible. Large areas with the same input values generate repeated ciphertext patterns, so the outline of the original image remains recognizable.

Image demonstrating visible patterns after ECB encryption
ECB can conceal values while still exposing structure.

Pattern leakage is not limited to images. Structured records, protocol fields, repeated headers, and predictable values can also reveal relationships to an observer. NIST’s 2024 review recommended considering ECB disallowed for encrypting secrets, while recognizing narrow non-confidentiality uses such as certain challenge-response or IV-generation applications.

How CBC mode works

Cipher Block Chaining mode combines each plaintext block with the previous ciphertext block before encryption. The first block uses an initialization vector. This chaining prevents identical plaintext blocks from automatically producing identical ciphertext blocks.

Diagram showing ciphertext block chaining in CBC mode
CBC uses the previous ciphertext block as part of the next encryption step.

The IV is not a secret, but it must be generated according to the mode’s requirements. For CBC encryption, NIST SP 800-38A requires the IV to be unpredictable. Reusing a predictable IV can expose relationships between messages.

CBC encryption is sequential because each ciphertext block depends on the one before it. Decryption can be parallelized because the ciphertext blocks are already available.

Why CBC is not enough by itself

CBC addresses ECB’s repeated-block problem, but it does not authenticate the ciphertext. An attacker may be able to modify encrypted data in ways that cause controlled or detectable changes after decryption. Systems that expose different behavior for invalid padding can also create padding-oracle vulnerabilities.

If CBC must be used, it needs a separate, correctly implemented authentication mechanism. OWASP recommends Encrypt-then-MAC when authenticated modes are unavailable. The encryption and authentication keys must be independent, and authentication should be verified before decrypted plaintext is processed.

These details are easy to get wrong. A standard, well-reviewed AEAD implementation removes much of the composition risk.

Prefer authenticated encryption for new designs

NIST states that integrated authenticated encryption should be the default choice wherever feasible. Its approved general-purpose AEAD techniques include GCM and CCM. These modes provide confidentiality while also producing an authentication tag that lets the recipient detect modification.

OWASP similarly recommends authenticated modes such as GCM and CCM as the first preference. The exact choice still depends on the protocol, platform, hardware support, nonce-management design, message size, and applicable validation requirements.

Authenticated encryption is not automatic protection against every implementation mistake. GCM, for example, depends on nonce uniqueness for a given key. Reusing a nonce can undermine both confidentiality and authentication.

Which mode should you choose?

  1. For a new general-purpose design: use a standard AEAD construction supported by a maintained cryptographic library, commonly AES-GCM or AES-CCM.
  2. For an existing CBC system: verify unpredictable IV generation, padding behavior, independent authentication keys, Encrypt-then-MAC ordering, and fail-closed error handling before planning migration.
  3. For existing ECB-encrypted secret data: inventory where it is used and migrate to an appropriate authenticated mode. Do not merely change the mode for new records without a plan for old ciphertext and key versioning.
  4. For specialized uses: follow the governing standard rather than applying general application-encryption advice to disk encryption, key wrapping, format-preserving encryption, or deterministic encryption.

The bottom line

CBC is safer than ECB for conventional confidentiality, but “CBC instead of ECB” is no longer the best stopping point. New systems should usually start with authenticated encryption. Existing CBC systems need explicit authentication and careful implementation. ECB should not be used to encrypt secret data.

Mode selection is one part of protecting sensitive values. Runtime controls also need to determine when an authorized identity receives cleartext and when it receives an encrypted, tokenized, or masked representation. Learn more about Runtime Data Protection.

Sources