Twofish Explained: The Free Cipher That Lost to AES and Still Deserves Your Attention

Twofish explained in plain terms means understanding the cipher that came within a whisker of becoming the world’s standard: a fast, free, unpatented block cipher that reached the finals of the AES competition and lost to Rijndael by a narrow margin. The central question is whether losing that contest means Twofish is a bad cipher, and the answer is no, it means it was second best in a field of giants, and second best in that field is still excellent.

Most engineers have never used Twofish, and most have never needed to. AES won, AES is everywhere, and AES is the right default for almost everything. But Twofish is still there, still unbroken, still free to use, and still the right answer in a handful of situations where AES is not the obvious choice, which is why it deserves a second look rather than a footnote.

This article makes the case for Twofish, explains what it is, how it works, and where it still earns its place in a world that chose AES.

Key takeaways

  • Twofish is a 128-bit block cipher that reached the AES finals in 2000.
  • It is free and unpatented, with no licensing costs or restrictions.
  • It uses key-dependent substitution boxes, unique among the finalists.
  • It has never been seriously broken in over twenty-five years.
  • It still suits niche uses where AES is unavailable or unsuitable.

What Twofish is

Twofish is a symmetric block cipher designed by Bruce Schneier and his team, published in 1998 as a candidate for the Advanced Encryption Standard. It encrypts data in 128-bit blocks, accepts keys of 128, 192, or 256 bits, and runs a sixteen-round Feistel network, the same broad structure as DES, rebuilt with modern ideas at every step.

Its signature feature is key-dependent substitution boxes. Where most ciphers use fixed lookup tables, Twofish builds its tables from the key itself, so the tables are different for every key and an attacker cannot precompute anything about them. It is an elegant idea, and it was unique among the five AES finalists.

The design is deliberately conservative. The team chose a sixteen-round network, a strong key schedule, and a whitening step that mixes key material into the data before the first round and after the last, which means even an attacker who breaks a round or two still faces the full cipher. Conservative design is why Twofish has aged so well.

It lost the AES competition for practical reasons, not cryptographic ones. The judges found Rijndael faster on the hardware of the day, simpler to implement, and easier to analyse, and those qualities mattered more than Twofish’s marginal security advantages. Losing to Rijndael is no disgrace; it is like losing a sprint to an Olympic champion.

It is free in every sense that matters. Twofish was released without patents and without licensing restrictions, and its reference implementation is public domain, which means anyone can use it, ship it, and build on it without asking permission or paying anyone, a freedom that still matters in open-source projects.

Our guide to AES encryption explains the cipher that won the contest Twofish entered, and our guide to hashing explains the one-way functions that ciphers like Twofish are often paired with.

How Twofish works

Everything starts with the key schedule, which is unusually thorough. Twofish expands the key into forty round subkeys and four key-dependent substitution boxes, using the key itself as the raw material, so the setup is slower than AES but the resulting cipher is tailored to its key in a way no fixed-table cipher can match.

Encryption runs sixteen rounds of a Feistel network. Each round splits the block in half, passes one half through a function built from the key-dependent boxes and a mixing step, and combines the result with the other half, swapping the halves as it goes. After sixteen rounds, the two halves are swapped one final time and whitened with key material.

The function at the heart of each round is where the design shines. It takes the input through the substitution boxes, mixes the result with a maximum distance separable matrix, and combines it with a pseudo-Hadamard transform, which spreads the influence of every input bit across the output. The combination is designed so that a change in one bit of the input avalanches through the whole block.

Decryption is the same network run backwards. The Feistel structure means the same code, with the subkeys in reverse order, decrypts what encryption produced, which is why Feistel ciphers are popular: one implementation serves both directions, and the key schedule is the only part that changes.

The security argument rests on the key-dependent boxes. Because the boxes are built from the key, an attacker cannot study them in advance, cannot build tables against them, and cannot reuse work from one key against another, which removes a whole class of attacks that fixed-table ciphers must defend against.

A dark office desk with two brass keys glowing green under a lamp, a locked steel box between them
A dark office desk with two brass keys glowing green under a lamp, a locked steel box between them, shows how Twofish works: every key builds its own lock, so no two locks are ever the same.

Comparing Twofish with other block ciphers

Twofish is one of several block ciphers a designer can choose, and each was built with a different emphasis. AES is the standard, fast everywhere and analysed by everyone, Blowfish is Twofish’s older sibling and simpler but limited to 64-bit blocks, and ChaCha20 is a stream cipher that needs no special hardware, and each approach trades speed for simplicity in a different way.

The table below sets out the main contrasts between the leading approaches.

Aspect Twofish AES Blowfish
Block size 128 bits 128 bits 64 bits
Key-dependent boxes Yes No Yes
Patent status Free Free Free
Hardware support None Built into CPUs None
Best for Niche and legacy use Everything Legacy systems

The practical result is that Twofish is the right choice where AES is unavailable and a modern 128-bit cipher is needed, AES suits everything else, and Blowfish fits only legacy systems that cannot change.

Where Twofish is used

File encryption tools are its most visible home. VeraCrypt, the successor to TrueCrypt, offers Twofish as one of its ciphers, and users who distrust the ubiquity of AES, or who simply want a second opinion on their data, choose it for their encrypted volumes. The choice is a statement as much as a technical decision.

Open-source projects use it where licensing clarity matters. Because Twofish is unpatented and its reference code is public domain, projects that must be certain about intellectual property choose it over ciphers with murkier histories, and the freedom from licensing is worth more than the speed AES would offer.

Legacy systems keep it running. Software written in the early 2000s that chose Twofish before AES was standardised still uses it today, and the cipher’s stability means those systems have never needed to change, which is a quiet endorsement of the design.

Password managers and backup tools have used it as an alternative cipher. Some tools offer Twofish alongside AES so that users can choose, and the existence of the choice is itself a security argument: a system that supports two ciphers is harder to break than one that depends on a single algorithm.

Teaching is its quietest use. Twofish is the standard example in courses of a well-designed Feistel cipher with key-dependent tables, and students who implement it learn more about cipher design than they would from the simpler, more regular structure of AES.

Strengths and limits

The greatest strength of Twofish is that it has never been broken. Twenty-five years of cryptanalysis have produced only theoretical attacks that require absurd amounts of data, and the cipher’s conservative design has aged better than almost any of its contemporaries, which is a record few ciphers can match.

It is also a strength that it is free. No patents, no licences, no royalties, and public-domain reference code mean that Twofish can be used anywhere, by anyone, for any purpose, which is a freedom that matters more than it might seem in a field where licensing has killed good designs before.

The limits are real, though, and the biggest is the absence of hardware support. Modern processors accelerate AES in silicon, and Twofish runs entirely in software, which makes it slower on the platforms where speed matters most. It is also less studied than AES, which means less confidence, even if the record so far is clean.

Twofish checklist

  • Use AES as the default; choose Twofish only with a reason.
  • Prefer it where licensing clarity or a second cipher matters.
  • Use a 256-bit key for maximum security margin.
  • Pair it with an authenticated mode; Twofish alone gives no tamper evidence.
  • Do not use it for new high-performance systems; AES is faster.
  • Keep the implementation reviewed; use a well-known library.
  • Remember it has no hardware acceleration on modern CPUs.
  • Consider it for encrypted volumes alongside AES.
  • Revisit the choice yearly; the field moves on even when ciphers do not.

Frequently asked questions

What is Twofish in simple terms?

It is a free, unpatented block cipher that reached the finals of the AES competition in 2000, built on a sixteen-round Feistel network with key-dependent substitution boxes.

Why did Twofish lose to AES?

Because Rijndael, the winner, was faster on the hardware of the day, simpler to implement, and easier to analyse. The decision was about practicality, not about Twofish being insecure.

Is Twofish still secure?

Yes. In over twenty-five years, no practical attack has been found, and the best known attacks are theoretical, requiring more data than any real system would ever encrypt.

What are key-dependent substitution boxes?

They are lookup tables built from the encryption key itself, so every key produces different tables, which prevents an attacker from precomputing anything about the cipher.

When should I use Twofish?

When you need a second cipher alongside AES, when licensing clarity matters, or when maintaining a legacy system that already uses it.

Should new projects choose Twofish over AES?

Almost never. AES is faster, better studied, and hardware-accelerated, and it is the right default. Twofish is the right answer only when a specific reason points to it.

The bottom line

Twofish explained in one line is this: the cipher that came second in the most important contest in cryptography, and stayed unbroken for a quarter of a century afterwards.

It is the free, conservative, overlooked alternative to AES, and the reason it still deserves attention is that a world with two good ciphers is safer than a world with one.

This article is general information about how Twofish works, not advice about choosing encryption for a particular system.

Latest articles

Scroll to Top