function calculateRafter() {
var span = parseFloat(document.getElementById('buildingSpan').value);
var pitch = parseFloat(document.getElementById('roofPitch').value);
var overhang = parseFloat(document.getElementById('overhangLength').value) || 0;
var ridge = parseFloat(document.getElementById('ridgeThickness').value) || 0;
if (isNaN(span) || isNaN(pitch) || span <= 0 || pitch < 0) {
alert("Please enter valid positive numbers for Span and Pitch.");
return;
}
// 1. Calculate the actual horizontal run (Half span minus half ridge thickness)
// Convert ridge to feet
var ridgeFt = ridge / 12;
var run = (span / 2) – (ridgeFt / 2);
// 2. Calculate the Rise
var slope = pitch / 12;
var rise = run * slope;
// 3. Calculate the Hypotenuse (Theoretical rafter length from ridge to wall plate)
var rafterHypotenuse = Math.sqrt(Math.pow(run, 2) + Math.pow(rise, 2));
// 4. Calculate Overhang Extension
// Overhang is horizontal, so we need the slope length of that overhang
var overhangFt = overhang / 12;
var overhangSlopeLength = overhangFt * Math.sqrt(1 + Math.pow(slope, 2));
// 5. Total Length
var totalLengthFt = rafterHypotenuse + overhangSlopeLength;
// Format to Feet and Inches for construction
var totalFeet = Math.floor(totalLengthFt);
var totalInches = (totalLengthFt – totalFeet) * 12;
var formattedResult = totalFeet + "' " + totalInches.toFixed(2) + "\"";
// Calculate Angle
var angle = Math.atan(slope) * (180 / Math.PI);
var diagonalFactor = Math.sqrt(Math.pow(12, 2) + Math.pow(pitch, 2));
// Display Results
document.getElementById('totalLengthDisplay').innerText = formattedResult;
document.getElementById('runDisplay').innerText = run.toFixed(3);
document.getElementById('riseDisplay').innerText = rise.toFixed(3);
document.getElementById('angleDisplay').innerText = angle.toFixed(2);
document.getElementById('factorDisplay').innerText = diagonalFactor.toFixed(3);
document.getElementById('rafterResult').style.display = 'block';
}
How to Calculate Rafter Length: A Builder's Guide
Calculating the correct rafter length is critical for structural integrity and a professional roof profile. Whether you are building a shed, a garage, or a home, understanding the relationship between span, run, and pitch will save you time and material waste.
Key Definitions in Roof Framing
Span: The total width of the building from the outside of one wall plate to the outside of the opposite wall plate.
Run: Half of the span (minus half the thickness of the ridge board). This is the horizontal distance the rafter covers.
Pitch: The slope of the roof expressed as inches of vertical "rise" for every 12 inches of horizontal "run" (e.g., 6/12 pitch).
Overhang: The horizontal distance the roof extends beyond the exterior walls to protect the siding and foundation.
The Mathematical Formula
Most modern rafter calculations rely on the Pythagorean Theorem ($a^2 + b^2 = c^2$). In roofing terms:
Rafter Length² = Run² + Rise²
To find the total board length required, you must also add the slope-length of the overhang and account for the thickness of the ridge board where the two rafters meet at the peak.
Example Calculation
Suppose you have a building with a 20-foot span and a 5/12 pitch, with a 12-inch overhang.
Determine Run: Half of 20′ is 10′. Subtracting 0.75″ (half of a standard 1.5″ ridge) gives us 9.9375 feet.
Always measure from the outside of the wall plate. Remember that "Rafter Length" calculated here is the measurement from the ridge cut to the plumb cut of the birdsmouth. When ordering lumber, always round up to the next standard board size (e.g., if you need 11′ 10″, buy a 14-foot board to allow for waste and precise cuts).