Productivity and Utilities

Cache Replacement Policy Simulator

Enter a page reference sequence and a cache size to see how five replacement policies compare.

Your numbers

Example sequence. Page numbers or keys separated by spaces or commas, up to 200 references.

How many different pages fit in the cache at once, from 1 to 12.

Result

Misses with the optimal policy

9

20 references, 6 different pages, 3 frames.

FIFO misses
15
LRU misses
12
LFU misses
11
Clock misses
14
Optimal misses
9

All five policies

PolicyHitsMissesHit rateEvictions
FIFO51525.0%12
LRU81240.0%9
LFU91145.0%8
Clock61430.0%11
Optimal11955.0%6

LRU, step by step

StepPageResultFramesEvicted
17Miss7 - -
20Miss7 0 -
31Miss7 0 1
42Miss2 0 17
50Hit2 0 1
63Miss2 0 31
70Hit2 0 3
84Miss4 0 32
92Miss4 0 23
103Miss4 3 20
110Miss0 3 24
123Hit0 3 2
132Hit0 3 2
141Miss1 3 20
152Hit1 3 2
160Miss1 0 23
171Hit1 0 2
187Miss1 0 72
190Hit1 0 7
201Hit1 0 7
How this was calculated
  1. Every reference is either a hit (the page is already in a frame) or a miss. A miss fills an empty frame, or evicts one page chosen by the policy.
  2. FIFO evicts the page that has been in the cache longest. LRU evicts the page unused for the longest time. LFU evicts the page used the fewest times since it was loaded, breaking ties by least recent use. Clock gives each page a second chance with a reference bit. Optimal looks ahead and evicts the page whose next use is farthest away.
  3. The optimal policy needs the future, so it is a floor for comparison, not something a real cache can do. Clock details: a loaded or hit page gets bit 1, the hand clears bits as it passes and replaces the first page with bit 0.

Calculated using SumPanda.com · https://sumpanda.com/cache-replacement-policy-simulator/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the cache replacement policy simulator

  1. Enter the reference sequence: the pages, blocks or keys that are asked for, in order, separated by spaces or commas.
  2. Set the cache size in frames, from 1 to 12.
  3. Choose which policy's steps to show in the detailed table. The summary table always compares all five.
  4. Read the hits, misses and evictions for each policy, then follow the step table to see what is in the cache after every reference.

Formula

hit: the page is already in a frame, nothing changes except its use count and time

miss: the page takes an empty frame, or the frame of the victim the policy picks

FIFO victim = oldest loaded; LRU = longest unused; LFU = fewest uses, ties by LRU; Clock = first page with bit 0; Optimal = used farthest in the future

The hit rate is hits divided by the number of references. Optimal needs to see the future, so it is a floor to compare against, not a policy a real system can use.

A textbook sequence with 3 frames

The 20 references 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 with 3 frames give 15 misses under FIFO, 12 under LRU, 11 under LFU, 14 under Clock and 9 under Optimal. Optimal has 11 hits, a hit rate of 55%.

The sequence 1 2 3 4 1 2 5 1 2 3 4 5 shows Belady's anomaly: FIFO has 9 misses with 3 frames but 10 misses with 4 frames, so more memory made it worse. LRU and Optimal can never behave that way.

How the policies differ

FIFO ignores how a page was used and so can throw out a page that is needed constantly. LRU assumes the recent past predicts the near future, which often holds. LFU favors pages used many times, but a page that was popular long ago can stay far too long. Clock approximates LRU cheaply with one reference bit per page: a page gets a second chance if it was used since the hand last passed.

The same ideas run browsers, databases, processors and content networks. To see how keys spread over several cache nodes, use the Consistent Hash Ring Simulator, and for queues in general the Little's Law Calculator.

Rules for ties and starts

Empty frames fill from the first one. If two pages tie on the policy's measure, the rule is stated in the formula: LFU breaks ties by least recent use and Optimal evicts the page loaded longest ago when several are never used again. A loaded or hit page gets the Clock bit 1, and the hand moves on past the frame it fills.

Assumptions and limits

  • References are compared as text, so 7 and 07 are different pages.
  • Each reference is one page and the cache holds distinct pages only.
  • LFU counts uses only while a page is in the cache; the count starts again when it is loaded.
  • There is no cost to a miss other than the count, and write-back and prefetching are not modeled.
  • At most 200 references of up to 12 characters each are accepted.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

Why can the optimal policy never lose?

It always removes the page that will not be needed for the longest time. No other choice can leave a better cache, which the tests confirm by searching every possible choice on short sequences.

What is the Belady anomaly?

It is a case where a larger cache gives more misses. FIFO can show it, as the second preset does, but LRU and Optimal cannot.

Why does the Clock count differ from LRU?

Clock only knows whether a page was used since the hand last looked, not when, so it picks a victim less precisely. Its answer is usually between FIFO and LRU.

Does a bigger cache always help?

For LRU and Optimal, never hurts. For FIFO it usually helps, but the anomaly shows it is not guaranteed.