---
title: "Key Length and Security | FiveStudy"
description: "Why an n-bit key has 2^n possible values, why brute force needs 2^(n-1) guesses on average, the speed cost of longer keys, and why AES and RSA lengths cannot be compared."
url: https://fivestudy.com/guides/ap-cybersecurity-5-4-b-key-length-and-security
---

[AP Cybersecurity](https://fivestudy.com/ap-cybersecurity) · Study guide

# Key Length and Security

[Figure: FiveStudy]

FiveStudy

AP® Cybersecurity · Unit 5 · Applications, Data & Cryptography

AP® Cybersecurity · Unit 5 · Applications, Data & Cryptography

# Key Length and Security

Why a longer key means a larger keyspace, how many guesses a brute-force attack needs on average, the cost of longer keys, and why key lengths only compare within one algorithm.

1. Keyspace grows by doubling 2. How many guesses on average 3. Longer keys cost time 4. Recommendations keep rising 5. Compare within one algorithm 6. Worked examples 7. Common mistakes

## 1 Keyspace grows by doubling

Longer keys produce larger keyspaces. For binary keys, an ***n*-bit key has a keyspace of 2^(*n*)**: each bit has two choices, so every added bit doubles the number of possible keys.

**Figure 1.** Adding one bit gives every old key two versions, one starting with 0 and one with 1, so the keyspace doubles.

## 2 How many guesses on average

An adversary using software to guess an *n*-bit key will find it, on average, after **2^(*n*) ÷ 2 = 2^(*n*−1) guesses**. The right key is equally likely to be anywhere in the search, so on average the search ends halfway through. The worst case is all 2^(*n*).

A real test: a program picked 2,000 random 12-bit keys and searched for each one from 0 upward.

| Measure | Result |
| --- | --- |
| Keyspace | 2^12 = 4,096 |
| Predicted average, 2^(n−1) | 2,048 guesses |
| Measured average | 2,060 guesses |
| Fastest and slowest searches | 2 and 4,095 guesses |

At a trillion guesses per second, here is the average search time:

| Key length (bits) | Keyspace | Average guesses | Average time |
| --- | --- | --- | --- |
| 8 | 2^8 = 256 | 2^7 | less than a second |
| 16 | 2^16 = 65,536 | 2^15 | less than a second |
| 56 | 2^56 = 7.2 × 10^16 | 2^55 | about 10 hours |
| 128 | 2^128 = 3.4 × 10^38 | 2^127 | about 5.4 × 10^18 years |
| 256 | 2^256 = 1.2 × 10^77 | 2^255 | about 1.8 × 10^57 years |

## 3 Longer keys cost time

Longer keys are more secure, but they also require **more time to encrypt and decrypt**. AES-256 runs 14 rounds of scrambling per block instead of AES-128's 10. For RSA the cost grows much faster: doubling an RSA key from 2048 to 4096 bits makes each decryption several times slower, which matters on a busy server or a small device.

## 4 Recommendations keep rising

Processing power and efficiency keep improving, so software guesses keys faster every year. Key-length recommendations for both symmetric and asymmetric algorithms are therefore **periodically increased**.

| Then | What happened | Now |
| --- | --- | --- |
| 56-bit DES keys were the U.S. standard from 1977 | In 1998 a purpose-built machine found a DES key in 56 hours | AES with 128-bit or longer keys |
| 512-bit RSA keys were common in the 1990s | A 512-bit RSA key was broken in 1999 | 2048-bit RSA is the minimum; 3072 or more for long-term secrets |

## 5 Compare within one algorithm

Key-length comparison is only valid for keys of the **same algorithm**.

- An AES 256-bit key is more secure than an AES 128-bit key.
- An RSA 4096-bit key is more secure than an RSA 2048-bit key.
- RSA and AES keys **cannot be compared directly**. RSA keys must be much longer because attackers do not search every possible RSA key; they use math shortcuts. A 2048-bit RSA key is *not* sixteen times stronger than a 128-bit AES key.

The key idea

An *n*-bit key has 2^(*n*) possible values, and a brute-force search needs 2^(*n*−1) guesses on average. Longer keys are more secure but slower, recommended lengths rise as computers get faster, and lengths only compare within the same algorithm.

## 6 Worked examples

Worked Example 1 Compute the keyspace

### A 20-bit key

A practice cipher uses a 20-bit key. What is its keyspace, and how many guesses does brute force need on average?

1. 1

   Keyspace: 2^20 = 1,048,576.

2. 2

   Average: 2^19 = 524,288 guesses.

**Answer:** 1,048,576 keys; 524,288 guesses on average.

Worked Example 2 Compare lengths

### How much bigger?

How many times larger is the keyspace of a 64-bit key than a 60-bit key?

1. 1

   Each extra bit doubles the keyspace.

2. 2

   Four extra bits: 2^4 = 16.

**Answer:** 16 times larger, and 16 times as long to search.

Worked Example 3 Valid comparison?

### RSA versus AES

A student says, “RSA-2048 is far more secure than AES-256, because 2048 is bigger than 256.” Evaluate the claim.

1. 1

   Key lengths only compare within the same algorithm.

2. 2

   RSA and AES are attacked in completely different ways, so their bit counts do not measure the same thing.

**Answer:** Invalid. RSA and AES keys cannot be compared by length.

Worked Example 4 Choose a length

### Long-term records

A hospital must keep encrypted records private for 30 years. Its policy allows AES-128 or AES-256. Which should it choose, and what is the cost?

1. 1

   Computers will keep getting faster, and recommendations rise over time.

2. 2

   A 30-year secret needs a large safety margin: AES-256.

3. 3

   The cost is more time to encrypt and decrypt, which modern servers handle easily.

**Answer:** AES-256, accepting a small speed cost for a margin that should last decades.

## 7 Common mistakes

Common Mistake 1 · Thinking doubling the bits doubles the keyspace

Adding *one* bit doubles it. Going from 128 to 256 bits multiplies the keyspace by 2^128.

Common Mistake 2 · Using 2^n for the average

The average brute-force search needs half of that: 2^(n−1) guesses.

Common Mistake 3 · Comparing lengths across algorithms

Only compare AES to AES or RSA to RSA.

Common Mistake 4 · Treating today's length as permanent

Faster computers push recommendations up. A key length that was fine years ago may not be now.

Explain key length like this

“A 256-bit AES key has 2^256 possible values, so a brute-force attack needs 2^255 guesses on average, far more than any computer can try. It is more secure than a 128-bit AES key but takes somewhat longer to encrypt and decrypt.”

Give the keyspace, the average number of guesses, and the trade-off, and compare only within one algorithm.

FiveStudy AP® Cybersecurity · Key Length and Security
