Cap (Clamp) a Value Between Limits

Excel Formulas › Min & Max

All versionsMINMAX

To force a number to stay within a floor and a ceiling — a percentage that can’t exceed 100, a bonus capped at $5,000, a quantity no less than zero — nest MIN and MAX. It’s the spreadsheet version of “clamp.”


Quick formula: to keep A2 between a low of 0 and a high of 100:
=MIN(MAX(A2, 0), 100)
MAX(A2, 0) lifts anything below 0 up to 0; the outer MIN(…, 100) pulls anything above 100 down to 100.

Functions used (tap for the full reference guide):

The example

Raw values capped to the 0–100 range.

AB
1RawCapped (0-100)
2-150
37272
4118100

The formula

The clamp formula:

=MIN(MAX(A2, 0), 100) // -15 → 0, 72 → 72, 118 → 100

How it works

Two functions enforce the two limits:

  1. MAX(A2, 0) handles the floor: if A2 is below 0, MAX returns 0; otherwise it returns A2.
  2. MIN(…, 100) handles the ceiling: if the result is above 100, MIN returns 100; otherwise it passes through.
  3. Together they guarantee the output never leaves the 0–100 band — values inside the range are untouched.
  4. A neat one-function alternative is =MEDIAN(0, A2, 100), which returns the middle of the three — also a clamp.

Try it: interactive demo

Live demo

Drag the raw value; watch it get clamped to 0–100.

Capped:

Variations

One-function clamp with MEDIAN

The median of {low, value, high} is the clamp:

=MEDIAN(0, A2, 100)

Floor only (never below zero)

Just the lower bound:

=MAX(A2, 0)

Ceiling only (cap a bonus)

Just the upper bound:

=MIN(A2, 5000)

Pitfalls & errors

Order matters for readability, not result. MIN(MAX(x,lo),hi) and MAX(MIN(x,hi),lo) give the same answer — pick one and be consistent.

Swapped limits. If your low is accidentally above your high, the clamp returns the wrong bound. Make sure low ≤ high.

MEDIAN clamp needs exactly three arguments — low, value, high. Adding more changes the meaning.

Practice workbook

📊
Download the free Cap (Clamp) a Value Between Limits practice workbook
Raw values with the live MIN/MAX clamp, the MEDIAN one-function version, and floor/ceiling-only variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I limit a value to a range in Excel?
Nest MIN and MAX: =MIN(MAX(A2, low), high). MAX enforces the floor and MIN enforces the ceiling, so the value is clamped to the band.
Is there a single-function way to clamp a value?
Yes: =MEDIAN(low, value, high) returns the middle of the three, which equals the clamped value.
How do I stop a value from going below zero?
Use just the floor: =MAX(A2, 0) returns 0 for any negative input and the value otherwise.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: Round up or down · Minimum value with criteria · IF with AND / OR

Function references: MIN · MAX · MEDIAN