The volume of a cylinder is V = π × r² × h — multiply Pi by the radius squared, then by the height. For a cylinder with a radius of 5 cm and a height of 10 cm, that's 785.40 cm³ (about 0.785 liters). Whether you're filling a water tank, designing a pipe, or building a geometry calculator, this formula is the starting point.
In this tutorial, you'll get the full formula breakdown, four worked examples in both metric and imperial units, a Python implementation, a unit conversion table, and a rundown of the most common mistakes people make.
Quick Reference
PropertyValueFormulaV = π × r² × hrRadius of the circular base (half the diameter)hPerpendicular height between the two basesπ3.14159265… (use math.pi in Python)Output unitsCubic units — cm³, m³, in³, ft³Best forTanks, pipes, pillars, cans, engine cylinders
What Is Cylinder Volume?
A cylinder is a 3D shape with two identical circular bases connected by a curved surface at a fixed distance apart. Volume measures how much space exists inside — in other words, how much liquid, gas, or material it can hold.
You'll run into cylinders constantly as a developer: rendering 3D objects, calculating fluid capacity for simulation apps, computing engine displacement, or building a geometry utility. Understanding the math underneath makes the code make sense.
For a thorough geometric definition, see cylinder geometry (Britannica).
The Cylinder Volume Formula — V = π × r² × h
The formula in full:
V = π × r² × h
Where:
V = volume (in cubic units, e.g. cm³)
π ≈ 3.14159 (Pi)
r = radius of the circular base (in cm, m, in, etc.)
h = height — the perpendicular distance between the two circular bases (same unit as r)
Why Does This Formula Work?
The area of a circle is A = π × r². Now imagine stacking an infinite number of these paper-thin circles from the bottom of the cylinder to the top. Each slice has area π × r², and the total "stack" has thickness h. Multiply the base area by the height, and you get the total volume. This principle — summing identical cross-sections — is called Cavalieri's principle and extends naturally into integral calculus.
For more on the underlying geometry, Khan Academy geometry has excellent interactive lessons on this exact derivation.
Using Diameter Instead of Radius
If you're measuring a physical object, it's often easier to measure the diameter (the full width across). Since radius = diameter ÷ 2:
V = π × (d/2)² × h
Or equivalently:
V = (π × d² × h) / 4
How to Calculate Cylinder Volume — Step by Step
Measure the radius. If you have the diameter, divide by 2.
Square the radius. Multiply r × r.
Multiply by π. Use 3.14159 for manual work, or math.pi in code.
Multiply by the height.
Label your answer with the correct cubic unit.
Example walkthrough: r = 5 cm, h = 10 cm
Step 1: r = 5 cm
Step 2: r² = 5 × 5 = 25
Step 3: π × r² = 3.14159 × 25 = 78.540 cm²
Step 4: V = 78.540 × 10 = 785.40 cm³
Done. The cylinder holds 785.40 cm³, which equals 0.785 liters.
Worked Examples in Metric and Imperial
Example 1 — Metric: A Storage Tin (cm → cm³ → liters)
A cylindrical tin has a radius of 4 cm and a height of 12 cm. How much does it hold?
V = π × 4² × 12
V = 3.14159 × 16 × 12
V = 3.14159 × 192
V = 603.19 cm³
Convert to liters: 603.19 ÷ 1,000 = 0.603 L (about 603 mL).
Example 2 — Imperial: A PVC Pipe Section (inches → in³ → gallons)
A pipe has an internal radius of 2 inches and is 36 inches long. What's its internal volume?
V = π × 2² × 36
V = 3.14159 × 4 × 36
V = 3.14159 × 144
V = 452.39 in³
Convert to US gallons: 452.39 ÷ 231 = 1.96 US gallons.
Example 3 — Real-World: A Cylindrical Water Tank (meters → liters)
A water tank has a radius of 0.75 m and a height of 2 m.
V = π × 0.75² × 2
V = 3.14159 × 0.5625 × 2
V = 3.14159 × 1.125
V = 3.534 m³
Convert to liters: 3.534 × 1,000 = 3,534 liters (about 933 US gallons).
This is the kind of calculation useful in agricultural irrigation systems, pool sizing, and residential rainwater harvesting setups.
Example 4 — Hollow Cylinder: Pipe Wall Volume
A hollow cylinder (like a metal pipe) has an outer radius R = 5 cm, an inner radius r = 4 cm, and a height of 20 cm.
The formula for a hollow cylinder is:
V = π × (R² - r²) × h
V = 3.14159 × (5² - 4²) × 20
V = 3.14159 × (25 - 16) × 20
V = 3.14159 × 9 × 20
V = 3.14159 × 180
V = 565.49 cm³
This gives you the volume of the pipe material itself — useful for calculating material weight or wall thickness in manufacturing.
For a deeper look at hollow cylinder formulas, see cylinder (MathWorld).
Calculating Cylinder Volume in Python
One of the first things you might do when working through geometry problems programmatically is build a small utility. Here's a clean Python implementation for both solid and hollow cylinders:
pythonimport math
def cylinder_volume(radius: float, height: float) -> float:
"""Calculate the volume of a solid cylinder.
Args:
radius: Radius of the circular base (any unit)
height: Perpendicular height (same unit as radius)
Returns:
Volume in cubic units matching your input unit
"""
if radius <= 0 or height <= 0:
raise ValueError("Radius and height must be positive numbers.")
return math.pi * radius ** 2 * height
def hollow_cylinder_volume(outer_radius: float, inner_radius: float, height: float) -> float:
"""Calculate the volume of a hollow cylinder (pipe/tube).
Args:
outer_radius: Outer radius R
inner_radius: Inner radius r (must be < outer_radius)
height: Height of the cylinder
Returns:
Volume of the cylindrical shell material
"""
if inner_radius >= outer_radius:
raise ValueError("Inner radius must be less than outer radius.")
return math.pi * (outer_radius ** 2 - inner_radius ** 2) * height
def cm3_to_liters(cm3: float) -> float:
return cm3 / 1000
def cm3_to_us_gallons(cm3: float) -> float:
return cm3 / 3785.41
--- Examples ---
v = cylinder_volume(5, 10)
print(f"Solid cylinder (r=5cm, h=10cm): {v:.2f} cm³ = {cm3_to_liters(v):.3f} L")
v_hollow = hollow_cylinder_volume(5, 4, 20)
print(f"Hollow cylinder (R=5, r=4, h=20): {v_hollow:.2f} cm³")
Output:
Solid cylinder (r=5cm, h=10cm): 785.40 cm³ = 0.785 L
Hollow cylinder (R=5, r=4, h=20): 565.49 cm³
For more on Python's math library, check out the #python and #math tags on DEV — there's great community content on numerical computing.
If you want to skip the manual implementation and get instant results for quick checks, the Cylinder Volume Calculator handles all unit combinations without needing to write any code — useful when you just need a sanity check on your numbers.
Unit Conversion Reference
FromToMultiply bycm³Liters (L)÷ 1,000cm³Milliliters (mL)× 1 (1 cm³ = 1 mL)m³Liters× 1,000m³cm³× 1,000,000in³cm³× 16.387in³US gallons÷ 231in³UK gallons÷ 277.42ft³Liters× 28.317ft³US gallons× 7.4805
Standard conversion constants sourced from standard units (NIST).
Quick memory aid: 1 cm³ = 1 mL exactly. So a cylinder with volume 500 cm³ holds exactly 500 mL = 0.5 liters. This makes metric cylinder calculations directly interchangeable with liquid measurements.
Real-World Applications
Engineering: Engine displacement is calculated as cylinder volume × number of cylinders. A 4-cylinder engine where each cylinder has a bore radius of 4.1 cm and stroke of 8 cm displaces V = π × 4.1² × 8 × 4 = 1,686 cm³ ≈ 1.7L.
Construction: Concrete pillars are cylinders. A pillar with radius 0.3 m and height 4 m uses V = π × 0.09 × 4 = 1.131 m³ of concrete (about 2.7 metric tons at 2,400 kg/m³).
DIY and home: Sizing a water butt, calculating aquarium volume, or working out how much soil fills a cylindrical planter all come down to this same formula.
Science and lab work: Graduated cylinders and test tubes are literal cylinders. Knowing the formula helps you cross-check volume readings against physical dimensions.
Software development: Volume calculations appear in physics engines, 3D rendering pipelines, simulation software, and any app that models fluid dynamics. Check out #tutorial on DEV for community examples of geometry in code.
Common Mistakes to Avoid
Using diameter as radius. This is the #1 error. If you measure across a pipe and get 10 cm, your radius is 5 cm. Plugging in 10 instead of 5 multiplies your volume by 4 — a massive overestimate.
Mixing units. Radius in centimeters and height in meters gives a meaningless result. Convert everything to the same unit before plugging into the formula.
Forgetting to square the radius. The formula is π × r² × h, not π × r × h. Squaring is non-optional — it's what gives the formula its circular base area.
Using slant height. For an oblique cylinder (one that leans), height is the perpendicular distance between the bases, not the length of the slanted side wall.
Rounding π too early. Using π = 3.14 instead of 3.14159 introduces ~0.05% error per calculation — small, but it accumulates in engineering contexts.
FAQs
What is the formula for the volume of a cylinder?
V = π × r² × h. Multiply Pi (≈ 3.14159) by the radius squared, then by the height. All measurements must be in the same unit. The result is in cubic units — cm³ if you measured in centimeters, m³ if in meters, etc.
How do I convert cylinder volume from cm³ to liters?
Divide the cm³ value by 1,000. One liter equals exactly 1,000 cm³ (also written as 1 dm³). So a cylinder measuring 2,500 cm³ holds 2.5 liters. This works because the metric system is designed so that volume and length units align perfectly.
What if I only have the diameter, not the radius?
Divide the diameter by 2 to get the radius, then apply the formula normally. You can also use the diameter form directly: V = (π × d² × h) / 4. Using diameter directly without halving it is one of the most common calculation errors.
How do I calculate the volume of a hollow cylinder?
Use V = π × (R² − r²) × h, where R is the outer radius and r is the inner radius. This gives you the volume of the cylindrical shell — the material between the outer and inner surfaces. It's used for pipes, tubes, and cylindrical pressure vessels.
What units does cylinder volume use?
Cubic units — always. If radius and height are in centimeters, volume is in cm³. In meters → m³. In inches → in³. You then convert to capacity units (liters, gallons) using the conversion table above.
How do I calculate cylinder volume in Python?
import math and use math.pi * radius*2 * height. The full reusable function is shown in the Python section above. For beginners learning this, the #beginners tag on DEV has great introductory programming resources.
**Can I use this formula for an oblique (tilted) cylinder?*
Yes — the formula V = π × r² × h still works, as long as h is the perpendicular height between the two bases, not the slant length of the side. This is the same principle that makes Cavalieri's theorem powerful: the volume depends only on the cross-section and the perpendicular height, not the tilt.
How many liters does a cylinder with a 10 cm radius and 30 cm height hold?
V = π × 10² × 30 = 3.14159 × 100 × 30 = 9,424.78 cm³ = 9.42 liters. That's roughly equivalent to a 9.4 L bucket — useful for sizing containers in DIY and agricultural contexts.
Wrapping Up
The cylinder volume formula — V = π × r² × h — is one of those geometric fundamentals that keeps showing up whether you're writing code, building something, or just solving a homework problem. The key things to remember:
Always use radius (not diameter) unless you adjust the formula
Keep all measurements in the same unit before calculating
1 cm³ = 1 mL — the metric system makes liquid conversions trivial
For hollow cylinders (pipes, tubes), use V = π × (R² − r²) × h
The Python code in this article gives you a clean, reusable starting point if you're building a geometry tool or utility script. For quick one-off calculations during development or testing, the Cylinder Volume Calculator is a fast sanity check that handles all major unit conversions instantly.

Top comments (0)