Calculating the exact length of roof rafters is critical for any framing project. This tool helps you determine the rafter length, the angle of the cut, and the total quantity of lumber required based on your building's dimensions.
Understanding Key Terms
Span: The total width of the building from the outside of one wall plate to the outside of the opposite wall plate.
Rise: The vertical height increase for every 12 inches of horizontal run (commonly referred to as the pitch, e.g., 6/12).
Run: Half of the span (minus half the ridge board thickness).
Overhang: The portion of the rafter that extends beyond the exterior wall.
On Center (OC): The distance from the center of one rafter to the center of the next.
The Math Behind Rafters
The calculation uses the Pythagorean theorem (a² + b² = c²). To find the rafter length:
Determine the Run (Span / 2).
Subtract half the thickness of the Ridge Board from the Run.
Calculate the Total Rise based on the pitch.
Calculate the hypotenuse: Length = √(Run² + Rise²).
Add the Overhang hypotenuse to get the full board length.
Practical Example
Imagine a shed with a 12-foot span and a 4/12 pitch. The run is 6 feet. If you have no ridge board and a 12-inch overhang, the base rafter length is roughly 6.32 feet. Adding the overhang (approx 1.05 feet at that angle) brings the total board length to about 7.37 feet. You would likely purchase 8-foot lumber to account for the birdsmouth cut and tail trimming.
function calculateRafters() {
var span = parseFloat(document.getElementById('buildingSpan').value);
var pitchRise = parseFloat(document.getElementById('roofRise').value);
var overhangInches = parseFloat(document.getElementById('overhang').value);
var ridgeThick = parseFloat(document.getElementById('ridgeThickness').value);
var roofLen = parseFloat(document.getElementById('roofLength').value);
var spacing = parseFloat(document.getElementById('rafterSpacing').value);
if (isNaN(span) || isNaN(pitchRise) || isNaN(overhangInches) || isNaN(ridgeThick) || isNaN(roofLen)) {
alert("Please fill in all fields with valid numbers.");
return;
}
// 1. Calculate the Adjusted Run (ft)
// Run is half the span minus half the ridge board thickness
var run = (span / 2) – ((ridgeThick / 12) / 2);
// 2. Calculate Angle
// Pitch is rise/12, so angle is atan(rise/12)
var angleRad = Math.atan(pitchRise / 12);
var angleDeg = angleRad * (180 / Math.PI);
// 3. Calculate Rafter Length (Hypotenuse of the run)
var rafterLength = run / Math.cos(angleRad);
// 4. Calculate Overhang Hypotenuse
var overhangRunFeet = overhangInches / 12;
var overhangHyp = overhangRunFeet / Math.cos(angleRad);
// 5. Total Length
var totalRafterLength = rafterLength + overhangHyp;
// 6. Total Rafter Count
// Rafters are needed on both sides.
// Count = (Length / Spacing) + 1, then double for gable sides.
var spacingFeet = spacing / 12;
var countPerSide = Math.ceil(roofLen / spacingFeet) + 1;
var totalCount = countPerSide * 2;
// Display Results
document.getElementById('resLength').innerHTML = rafterLength.toFixed(2) + " ft";
document.getElementById('resTotalLength').innerHTML = totalRafterLength.toFixed(2) + " ft";
document.getElementById('resAngle').innerHTML = angleDeg.toFixed(2) + "°";
document.getElementById('resCount').innerHTML = totalCount;
document.getElementById('results').style.display = 'block';
}