DEV Community

Cover image for How to Calculate How Much Mulch or Topsoil You Need
kandz
kandz

Posted on Originally published at tools.kandz.me

How to Calculate How Much Mulch or Topsoil You Need

Calculating how much mulch or topsoil to buy is a guessing game.

You measure in feet, but bags are sold in cubic feet, and bulk is sold in cubic yards. You guess wrong, and you're left with a pile of extra dirt or a half-empty garden bed.

Let's look at how to automate this calculation using JavaScript.


The Math (Step-by-Step)

  1. Calculate the Area: Length (ft) Γ— Width (ft) = Square Feet
  2. Determine the Depth: Convert inches to feet by dividing by 12. (e.g., 3 inches = 0.25 feet).
  3. Calculate Volume in Cubic Feet: Square Feet Γ— Depth (ft) = Cubic Feet
  4. Convert to Bags: Cubic Feet Γ· 2 = Number of 2-cu-ft bags (Always round up).
  5. Convert to Bulk (Cubic Yards): Cubic Feet Γ· 27 = Cubic Yards (Since 1 yard = 3ft, 3Β³ = 27).

The JavaScript Solution

Here is how you write a function to do this automatically, including rounding up to the nearest whole bag:

function calculateMulch(lengthFt, widthFt, depthInches) {
  // 1. Area
  const area = lengthFt * widthFt;

  // 2. Depth in feet
  const depthFt = depthInches / 12;

  // 3. Volume in cubic feet
  const cubicFeet = area * depthFt;

  // 4. Bags (2 cubic feet each) - rounded up
  const bagsNeeded = Math.ceil(cubicFeet / 2);

  // 5. Bulk (Cubic Yards) - usually rounded to 2 decimals
  const cubicYards = Number((cubicFeet / 27).toFixed(2));

  return {
    area,
    cubicFeet: Number(cubicFeet.toFixed(2)),
    bagsNeeded,
    cubicYards
  };
}

// Example: 10x5 bed, 3 inches deep
const result = calculateMulch(10, 5, 3);
console.log(`You need ${result.bagsNeeded} bags or ${result.cubicYards} cubic yards.`);
// Output: You need 7 bags or 0.46 cubic yards.
Enter fullscreen mode Exit fullscreen mode

Common Gotchas

  • Floating Point Math: Math.ceil() is critical for bags. If your math says you need 6.1 bags, you actually need to buy 7.
  • Weight Limits: Topsoil is much heavier than mulch. A cubic yard of mulch weighs about 800 lbs, but a cubic yard of topsoil can weigh over 2,000 lbs. If you're hauling it yourself, you might need to split the load.
  • Settling: Mulch settles. It's usually better to calculate for 3 inches rather than 2 to maintain a fresh look.

The Visual Way

If you don't want to write a script every time you go to the garden center, I built a free Mulch & Topsoil Yardage Calculator.

Try it here

100% client-side. Nothing uploaded.


Have you ever bought too much mulch and had to get rid of the leftovers? Let me know in the comments.

Top comments (0)