ForHosting KIT · Math

Largest cube in a cylinder

Find the biggest cube that fits inside a cylinder: with a radius of 2 and a height of 5, the edge is 2.828427 and the volume 22.627414. It works out for you whether the width or the height is the limit. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Radius
2
Height
5
You get
Edge
2.828427
Volume
22.627414

The answer has a clean closed form. The cube's base is a square inscribed in the circular cross-section, so its diagonal equals the circle's diameter and its side is r·√2; the cylinder's height then caps the edge when the cylinder is short. The limiting edge is therefore a = min(h, r·√2), and the volume is simply a³. Send two positive numbers and receive the exact edge length and cubic volume back, in whatever unit you supplied.

The geometry behind the formula

Picture the cube standing upright inside the cylinder, centered on the axis. Its bottom face is a square sitting inside the circular base of the cylinder. The largest square that fits inside a circle has its four corners touching the circumference, which means the square's diagonal equals the circle's diameter, 2r.

A square with diagonal 2r has side 2r divided by the square root of two, which simplifies to r·√2, roughly 1.4142 times the radius. That is the widest the cube can be regardless of height. But the cube also has to fit vertically: its edge cannot exceed the cylinder's height h.

So the binding edge is the smaller of the two constraints, a = min(h, r·√2). For a tall cylinder the width constraint governs and the edge is r·√2; for a short, wide cylinder the height governs and the edge is simply h. Both branches are handled by the same single formula, so you never need to decide which regime you are in — the capability does it for you.

What you send and what you get back

Both the edge and the volume are rounded to six decimal places. That rounding exists for reproducibility: floating-point arithmetic can produce slightly different trailing digits on different machines, and a capability whose output is compared byte to byte cannot afford that. Six decimals keeps far more precision than any real measurement carries.

The unit is entirely yours — send metres and the edge is in metres and the volume in cubic metres; send inches and you get inches and cubic inches. Nothing is converted behind your back.

Where this calculation earns its keep

This packing result shows up wherever a rectangular solid must live inside a round container. Woodworkers turning stock on a lathe use it to know the largest square-section blank they can start from: the biggest square beam hidden inside a round log of radius r is exactly r·√2 on a side, capped by the usable length. Machinists use it when milling a square or cubic feature from round bar stock, to check whether the stock has enough meat before committing to a cut.

Packaging engineers use it when a cubical product or insert must ship inside a cylindrical tube or drum, to pick the smallest container that still fits. In 3D printing and CNC nesting, it gives a fast conservative bound for fitting a cubic part into cylindrical raw material. Through the free on-page calculator, you get a single answer instantly, with no account and no code.

Square stock from a round log

Find the largest square-section beam that can be cut from a log of a given radius and usable length — the classic lathe and sawmill calculation.

Check bar stock before machining

Verify that round bar stock has enough material to mill a cubic feature of a given size before committing to the cut.

Fit a cubic product into a tube

Compute the largest cube that ships inside a cylindrical tube or drum to choose packaging dimensions with confidence.

What is the formula?

The cube's edge is a = min(h, r·√2): the width is limited by the largest square inscribed in the circular base, and by the cylinder's height. The volume is a³.

What unit is the result in?

The same unit you supplied: the edge is in that unit and the volume in that unit cubed. No unit conversion is applied.

How accurate is the result?

The edge and volume are computed exactly and rounded to six decimal places so the output is identical on every machine — far more precision than any physical measurement carries.

Why is the cube's edge the radius times √2?

The cube's base is the largest square that fits in the circle, with its four corners on the circumference, so its diagonal equals the diameter. A square with that diagonal has a side of r·√2, roughly 1.4142 times the radius.

What happens when the cylinder is short and wide?

Then the height limits the cube instead of the width, and the edge is simply the height. The calculation takes the smaller of the two limits, so you never have to decide which case applies.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/math/cubic-in-cylinder

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/math/cubic-in-cylinder \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"radius":2,"height":5}'
{
  "radius": 2,
  "height": 5
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.cubic_in_cylinder",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

The largest-cube-in-a-cylinder API answers a classic packing question: given a cylinder defined by its radius and height, what is the biggest cube that fits entirely inside it? The same deterministic code runs free in your browser on this page and costs $0.002 per request when you automate it through the API.

What you send and what you get back

The input is two fields, radius and height (the aliases r and h are also accepted), both required and both positive finite numbers in the same unit. The output is a clean JSON object with the radius and height you sent, the computed edge length of the largest inscribed cube, its volume, and the formula string used. Zero, negative, infinite or non-numeric values are rejected with a clear invalid_input error naming the offending field, instead of a misleading number.

Where this calculation earns its keep

Through the API at $0.002 per request, you can fold the check into a quoting tool or a material-selection pipeline without maintaining the formula yourself.

What does it cost?

$0.002 per request via the API. It is also free to run in your browser on this page.

What input does it accept?

Two fields: radius and height of the cylinder (aliases r and h), both positive finite numbers in the same unit.

What happens with zero, negative or non-numeric input?

The request is rejected with an invalid_input error naming the field. A cylinder needs a positive, finite radius and height, and the API says so instead of returning a misleading number.

Read the full KIT documentation →