Data Encryption Standard - DES
Data Encryption Standard, or else DES, is the foundation of modern block cyphers. We need to clearly understand how this works and the internals of this algorithm.
Understanding DES clearly makes it easy to get into modern encryption algorithms such as AES.
Feistel cipher networks
A Feistel cipher is a design model for building block ciphers. It takes a fixed-size block of plaintext, pushes it through several rounds of transformation, and produces a block of ciphertext of the same size.
Say we have a plaintext block of n bits. The first step is to split it down the middle into a left half and a right half, each n/2 bits.
<block size=20>L <br> n/2 bits</block> <block size=20>R <br> n/2 bits</block>
From there, the two halves go through a sequence of rounds. In each round, one half is fed through a round function, and the result is combined with the other half.
To go through the algorithm, first we need to understand the notation.
- The block size is
nbits, so each half isn/2bits. - The cipher runs for
rrounds. - Step numbers run from
0tor. At stepi, the two halves are Li and Ri. - Each round uses its own key. The key for round
iis Ki.
So, L0 and R0 are the halves of the plaintext, round 7 produces L7 and R7, and the last round produces Lr and Rr.
We will work through encryption first, then come back to decryption.
What happens in a single round?
Assume we are at round i. We start the round holding Li−1 and Ri−1, and we need to produce Li and Ri.
The left half is the easy one. The new left half is simply the old right half.
$$ L_i = R_{i-1} $$
The new right half is where the work happens. We take the old right half Ri−1, run it through the round function f along with this round's key Ki, and XOR the result with the old left half. Let's represent it mathematically.
$$ R_i = L_{i-1} \oplus f(R_{i-1}, K_i) $$
That is the whole round.
Here is round 1, taking L0 and R0 to L1 and R1 using key K1:
$$ \begin{aligned} L_1 &= R_0 \\ \\ R_1 &= L_0 \oplus f(R_0, K_1) \end{aligned} $$
Now round two.
Round 2 is the same picture shifted along by one. It takes the L1 and R1 we just produced, and uses a completely different key, K2.
$$ \begin{aligned} L_2 &= R_1 \\ \\ R_2 &= L_1 \oplus f(R_1, K_2) \end{aligned} $$
This goes up to the round r.
Here is the final round, with i = r:
$$ \begin{aligned} L_r &= R_{r-1} \\ \\ R_r &= L_{r-1} \oplus f(R_{r-1}, K_r) \end{aligned} $$
The final swap
After r rounds, we are holding Lr and Rr, but we are not quite done. One last operation produces the ciphertext: swap the two halves.
$$ \begin{aligned} L_{r+1} &= R_{r} \\ \\ R_{r+1} &= L_{r} \end{aligned} $$
The right output of the final round becomes the left half of the ciphertext, and the left output becomes the right half. The pair (Lr+1, Rr+1) is the encrypted block.
This swap looks arbitrary, and on its own it adds nothing to the security of the cipher. Its entire purpose is to make decryption work, which is the next section.
How decryption works
Encryption and decryption are the same structure. The only difference is that the round keys are fed in reverse order.
We know that for decryption we get the ciphertext.
As the first step, the ciphertext is split into its halves. We name these two parts as Lr+1 and Rr+1. This is because, at the end of the encryption, we obtained Lr+1 and Rr+1. We keep the same notation.
$$ \begin{aligned} R_r &= L_{r+1} \\ \\ L_r &= R_{r+1} \end{aligned} $$
This is basically undoing the swap, which was the last step in encryption.
Now Lr and Rr are the two parts we had at the end of the last encryption round.
From here, we run the rounds backwards, from i = r down to i = 1, using the keys in the reverse order.
Kr, Kr−1, …, K1 etc.
$$ \begin{aligned} R_{i-1} &= L_i \oplus f(R_i, K_i) \\ \\ L_{i-1} &= R_i \end{aligned} $$
We can see that these two operations have exactly the shape of the encryption round. The round function f is called on a value and a key, and its output is XORed with the other half.
We don't need to get the inverse of f. That means f does not need to be invertible.
We can choose any mixing function as f.
After working back through all r rounds, we get L0 and R0, which are the original plaintext halves. Join them, and we have the plaintext block.
To summarise the Feistel idea:
- Encryption: r rounds with keys K1 through Kr, then the final swap.
- Decryption: undo the final swap, then r rounds with keys Kr through K1.
- The structure is identical. Only the key order changes.
Now let us see what DES does with this structure.
From Feistel ciphers to DES
DES, the Data Encryption Standard, is a specific instance of a Feistel cipher.
Its core parameters:
Block size (n) = 64 bits
Key size = 64 bits
Number of rounds (r) = 16
So DES takes a 64-bit plaintext block and a 64-bit key, and produces a 64-bit ciphertext block.
The algorithm has three phases:
- Initial Permutation (IP)
- 16 Feistel rounds
- Final Permutation (FP)
Let's see them in deeply.
Step 1: The Initial Permutation
Before any round runs, DES rearranges the 64 input bits according to a fixed table.
| Output bits | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| 1–8 | 58 | 50 | 42 | 34 | 26 | 18 | 10 | 2 |
| 9–16 | 60 | 52 | 44 | 36 | 28 | 20 | 12 | 4 |
| 17–24 | 62 | 54 | 46 | 38 | 30 | 22 | 14 | 6 |
| 25–32 | 64 | 56 | 48 | 40 | 32 | 24 | 16 | 8 |
| 33–40 | 57 | 49 | 41 | 33 | 25 | 17 | 9 | 1 |
| 41–48 | 59 | 51 | 43 | 35 | 27 | 19 | 11 | 3 |
| 49–56 | 61 | 53 | 45 | 37 | 29 | 21 | 13 | 5 |
| 57–64 | 63 | 55 | 47 | 39 | 31 | 23 | 15 | 7 |
The left column gives a range of positions in the output.
The numbered columns give the input bits that fill them.
For example, output bit 1 takes input bit 58 while output bit 2 takes input bit 50, and the last output bit, 64, takes input bit 7.
What is the purpose of this rearrangement? Does this add cryptographic strength? No. It does nothing to enhance the strength of encryption.
The permutation is fixed, public and key-independent, so an attacker can simply undo it. It was included for hardware reasons.
In the 1970s, it made loading data into the encryption chip a byte at a time much simpler. That's the whole reason.
After the permutation, the 64-bit block is split into two 32-bit halves, L0 and R0.
<block size=32>L0 <br> 32 bits</block> <block size=32>R0 <br> 32 bits</block>
Now we are ready for the rounds.
Step 2: the 16 Feistel rounds
This is the core of DES. We have already gone through the Feistel rounds and have a good understanding of that. Let's see what happens here.
$$ \begin{aligned} L_i &= R_{i-1} \\ \\ R_i &= L_{i-1} \oplus f(R_{i-1}, K_i) \end{aligned} $$
All the cryptographic strength lives in the round function f. Let us open it up.
The round function takes the 32-bit right half and a 48-bit subkey, and returns 32 bits. It does this in four stages.
flowchart TD
R["R (32 bits)"] --> E["Expansion E"]
E --> X["XOR with subkey Ki"]
X --> S["S-box substitution"]
S --> P["Permutation P"]
P --> OUT["f(R, K) output (32 bits)"]
Stage 1: expansion
The right half (R) is 32 bits, and the subkey (K) is 48 bits. To do the XOR operation, both sides need to be the exact same length. The purpose of the expansion step is to stretch the 32 bits out to 48, using the expansion table:
| Output bits | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1 - 6 | 32 | 1 | 2 | 3 | 4 | 5 |
| 7 -12 | 4 | 5 | 6 | 7 | 8 | 9 |
| 13 - 18 | 8 | 9 | 10 | 11 | 12 | 13 |
| 19 - 24 | 12 | 13 | 14 | 15 | 16 | 17 |
| 25 - 30 | 16 | 17 | 18 | 19 | 20 | 21 |
| 31 - 6 | 20 | 21 | 22 | 23 | 24 | 25 |
| 37 - 42 | 24 | 25 | 26 | 27 | 28 | 29 |
| 43 - 48 | 28 | 29 | 30 | 31 | 32 | 1 |
The same table structure as above.
We can see the bits 32, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28 and 29 each appear twice,
This is how 32 bits become 48. It means a single input bit can influence two different S-boxes, which spreads its effect faster across the block. This is diffusion.
Stage 2: XOR with the subkey
We now have 48 bits from the expansion and a 48-bit subkey Ki. Now the sizes match, and we can do the XOR operation.
$$ \begin{aligned} result = R \oplus K_i \end{aligned} $$
Here result, R and k_i all are 48 bits in size.
Note that in this step we used the key.
Stage 3: S-box substitution
This is the heart of DES. The 48-bit XOR result is separated into eight groups of 6 bits.
Then each group is fed into its own S-box, a substitution table.
Each S-box eats 6 bits and emits 4.
48 bits = 8 groups x 6 bits
Group 1 -> S-box 1 -> 4 bits
Group 2 -> S-box 2 -> 4 bits
Group 3 -> S-box 3 -> 4 bits
Group 4 -> S-box 4 -> 4 bits
Group 5 -> S-box 5 -> 4 bits
Group 6 -> S-box 6 -> 4 bits
Group 7 -> S-box 7 -> 4 bits
Group 8 -> S-box 8 -> 4 bits
Total output: 8 x 4 = 32 bits
That is also where the 48 bits shrink back to the 32 bits the Feistel round needs.
Each S-box is a lookup table of 4 rows by 16 columns. Here is S-box 1:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 [ 14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7 ]
1 [ 0 15 7 4 14 2 13 1 10 6 12 11 9 5 3 8 ]
2 [ 4 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0 ]
3 [ 15 12 8 2 4 9 1 7 5 11 3 14 10 0 6 13 ]
The lookup is slightly odd. Given 6 input bits b1 b2 b3 b4 b5 b6:
- Row =
b1 b6, the first and last bits, giving a number from 0 to 3. - Column =
b2 b3 b4 b5, the middle four bits, giving a number from 0 to 15.
Worked example with the input 101101:
- Row =
b1 b6=11= 3 - Column =
b2 b3 b4 b5=0110= 6 - S-box 1, row 3, column 6 = 1
- Output =
0001
The S-boxes are the only nonlinear part of DES. Everything else, every permutation and expansion and XOR, is linear. Strip the S-boxes out and the whole cipher collapses into a system of linear equations over GF(2) that you could solve directly. The S-boxes are what provide confusion: they make the relationship between key, plaintext and ciphertext as tangled as possible.
The specific numbers in those tables were chosen by IBM's cryptographers with input from the NSA, and for years this made people deeply suspicious. The suspicion turned out to be backwards. When differential cryptanalysis was published openly in 1990, it became clear the S-boxes had been tuned to resist it, which means the designers already knew about the attack in the 1970s and said nothing. The tables were stronger than anyone outside had realised, not weaker.
Stage 4: the P permutation
The 32 bits coming out of the S-boxes are rearranged one more time:
P-box Permutation (P)
| Output bits | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| 1–8 | 16 | 7 | 20 | 21 | 29 | 12 | 28 | 17 |
| 9–16 | 1 | 15 | 23 | 26 | 5 | 18 | 31 | 10 |
| 17–24 | 2 | 8 | 24 | 14 | 32 | 27 | 3 | 9 |
| 25–32 | 19 | 13 | 30 | 6 | 22 | 11 | 4 | 25 |
This one does real work, unlike the initial permutation. It scatters the four output bits of each S-box so that they land in the inputs of several different S-boxes in the next round. Combined with the expansion, this is what guarantees the avalanche effect: after a handful of rounds, every bit of the plaintext and every bit of the key influences every bit of the ciphertext, and flipping one input bit flips roughly half the output bits.
The output of P is the output of f, and the round is done.
Step 3: the Final Permutation
After all 16 rounds, the halves go through the Feistel final swap, and the resulting 64-bit block is passed through the Final Permutation, which is just the inverse of the initial permutation:
Final Permutation (FP = IP⁻¹)
| Output bits | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| 1–8 | 40 | 8 | 48 | 16 | 56 | 24 | 64 | 32 |
| 9–16 | 39 | 7 | 47 | 15 | 55 | 23 | 63 | 31 |
| 17–24 | 38 | 6 | 46 | 14 | 54 | 22 | 62 | 30 |
| 25–32 | 37 | 5 | 45 | 13 | 53 | 21 | 61 | 29 |
| 33–40 | 36 | 4 | 44 | 12 | 52 | 20 | 60 | 28 |
| 41–48 | 35 | 3 | 43 | 11 | 51 | 19 | 59 | 27 |
| 49–56 | 34 | 2 | 42 | 10 | 50 | 18 | 58 | 26 |
| 57–64 | 33 | 1 | 41 | 9 | 49 | 17 | 57 | 25 |
What comes out is the 64-bit ciphertext.
The key schedule
We have been spending subkeys K1 through K16 freely, but the user supplies exactly one 64-bit key. The key schedule is what turns that single key into 16 different 48-bit subkeys.
Step 1: parity drop (PC-1)
Of the 64 key bits, 8 are parity bits, one per byte, used only for error detection. Permuted Choice 1 drops them and permutes what is left, giving 56 effective key bits:
Permuted Choice 1 (PC-1), 64 bits → 56
| Output bits | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| 1–7 | 57 | 49 | 41 | 33 | 25 | 17 | 9 |
| 8–14 | 1 | 58 | 50 | 42 | 34 | 26 | 18 |
| 15–21 | 10 | 2 | 59 | 51 | 43 | 35 | 27 |
| 22–28 | 19 | 11 | 3 | 60 | 52 | 44 | 36 |
| 29–35 | 63 | 55 | 47 | 39 | 31 | 23 | 15 |
| 36–42 | 7 | 62 | 54 | 46 | 38 | 30 | 22 |
| 43–49 | 14 | 6 | 61 | 53 | 45 | 37 | 29 |
| 50–56 | 21 | 13 | 5 | 28 | 20 | 12 | 4 |
Those discarded 8 bits are the reason DES has a 56-bit key rather than a 64-bit one, and that difference is what eventually killed it.
Step 2: split and rotate
The 56 bits are split into two 28-bit halves, C0 and D0. For each round, both halves are left-rotated, by either one or two positions depending on the round:
| Round | Rotation |
|---|---|
| 1, 2, 9, 16 | 1 position |
| All others | 2 positions |
Rotating gives round i its halves Ci and Di. Because the rotations accumulate, every round sees a different arrangement of the key bits. The totals add up to 28 over the 16 rounds, so after the last round C16 and D16 are back where they started, which is a tidy property for hardware that needs to run the schedule backwards for decryption.
Step 3: compression (PC-2)
The two 28-bit halves are concatenated back into 56 bits and passed through Permuted Choice 2, which both permutes them and throws 8 away, selecting 48 bits to be the subkey Ki:
Permuted Choice 2 (PC-2), 56 bits → 48
| Output bits | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1–6 | 14 | 17 | 11 | 24 | 1 | 5 |
| 7–12 | 3 | 28 | 15 | 6 | 21 | 10 |
| 13–18 | 23 | 19 | 12 | 4 | 26 | 8 |
| 19–24 | 16 | 7 | 27 | 20 | 13 | 2 |
| 25–30 | 41 | 52 | 31 | 37 | 47 | 55 |
| 31–36 | 30 | 40 | 51 | 45 | 33 | 48 |
| 37–42 | 44 | 49 | 39 | 56 | 34 | 53 |
| 43–48 | 46 | 42 | 50 | 36 | 29 | 32 |
Repeat for all 16 rounds and you have 16 unique 48-bit subkeys.
For decryption the schedule is identical. The same 16 subkeys are generated and simply applied in reverse, K16 first and K1 last. That is the Feistel property doing its job.
The complete picture
Putting every piece together:
flowchart TD
P["Plaintext (64 bits)"] --> IP["Initial Permutation (IP)"]
IP --> SP["Split into L0 and R0, 32 bits each"]
SP --> R1
subgraph rounds ["16 Feistel rounds"]
direction TB
R1["Round 1: L1 = R0, R1 = L0 XOR f(R0, K1)"] --> R2["Round 2: L2 = R1, R2 = L1 XOR f(R1, K2)"]
R2 --> DOTS["rounds 3 to 15"]
DOTS --> R16["Round 16: L16 = R15, R16 = L15 XOR f(R15, K16)"]
end
R16 --> SW["Final swap: R16 then L16"]
SW --> FP["Final Permutation (FP = inverse of IP)"]
FP --> C["Ciphertext (64 bits)"]
And inside every one of those rounds, f is expansion, then XOR with the subkey, then the eight S-boxes, then the P permutation.
Why DES is no longer secure
DES held up remarkably well against cryptanalysis. What it could not survive was arithmetic.
The problem is the 56-bit key. In 1977, 256 keys, about 72 quadrillion of them, was a genuinely enormous number. But brute force gets cheaper every year while the key length stays the same, and the gap closed in public:
- 1997 — the DESCHALL project recovered a DES key in 96 days, using spare cycles on thousands of volunteered computers.
- 1998 — the EFF built Deep Crack, purpose-built hardware costing around $250,000, and cracked a key in 56 hours.
- 1999 — Deep Crack combined with distributed.net brought it down to 22 hours.
That last result is the one that mattered. It showed a modestly funded organisation could break DES in under a day, which is to say DES no longer protected anything. Today the same search is a routine job for a GPU rig or a cloud bill.
There are also structural attacks, though they are the less urgent problem:
- Differential cryptanalysis needs about 247 chosen plaintexts.
- Linear cryptanalysis needs about 243 known plaintexts.
Both are faster than brute force on paper and both are useless in practice, because no attacker gets to collect trillions of chosen plaintexts under a key you are still using. They matter as a measurement: they show the internals of DES are not as strong as a modern cipher's, even setting the key length aside.
What came next
The industry's immediate answer to the key length problem was to run DES three times with different keys, giving Triple DES. It is not a new algorithm, just DES applied repeatedly, and it bought the world roughly two more decades while better options matured. The details, including why it is Encrypt-Decrypt-Encrypt rather than the obvious Encrypt-Encrypt-Encrypt, and why running DES only twice buys you almost nothing, are worth an article of their own.
The real replacement came from a public competition. NIST opened it in 1997, and in 2000 announced the winner: Rijndael, by the Belgian cryptographers Joan Daemen and Vincent Rijmen, standardised as AES in 2001. AES is not a Feistel cipher. It uses a substitution-permutation network, transforming the entire block every round instead of half of it. We will take that apart in a later article.
Final thoughts
DES is a beautiful piece of engineering. It took the Feistel structure and turned it into a practical, standardised algorithm that defended real data for decades, with every piece shaped around what 1970s hardware could actually do.
It also carries a lesson worth keeping: security is not permanent. An algorithm that was out of reach in 1977 was a weekend project by 1999, and nothing about the algorithm changed. Only the cost of computing did. That is precisely why modern ciphers use 128-bit and 256-bit keys, sized not for today's hardware but for decades of it.
If you want to understand modern cryptography, DES is the right place to start. Feistel networks, S-boxes, key schedules, diffusion and confusion all appear here first, and all of them turn up again in everything that followed. Get them straight here and AES will make far more sense.
Thanks for reading!