← All how-to recipes

How to clamp (limit) a value between a minimum and maximum

✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)

Force a number to stay within a range - anything below the floor becomes the floor, anything above the cap becomes the cap.

The formula

AppFormulaNotes
Excel (desktop)=MIN(MAX(A2,0),100)MAX raises up to the floor; MIN caps at the ceiling.
Google Sheets=MIN(MAX(A2,0),100)Identical.
LibreOffice Calc=MIN(MAX(A2,0),100)Identical.

How it works

MAX(A2,0) makes sure the value is at least 0; MIN(...,100) makes sure it's at most 100. A value of 150 is pulled down to the cap of 100. A value of -5 would be raised to 0, and anything already between 0 and 100 passes through unchanged.

Verified, not just documented

We ran =MIN(MAX(A2,0),100) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 100 — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned 100 for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.

Functions used

MIN · MAX — see full Excel, Google Sheets & LibreOffice compatibility for each.

Related recipes

Related comparisons