Building an IRC Table R602.7 Door & Window Rough Opening (R.O.) and Header Framing Solver in TypeScript
Framing mistakes around doors and windows almost always come from confusing nominal callout dimensions (like a 36" x 80" pre-hung door) with the framed Rough Opening (R.O.) and total header cut length including jack-stud
Framing mistakes around doors and windows almost always come from confusing nominal callout dimensions (like a 36" x 80" pre-hung door) with the framed Rough Opening (R.O.) and total header cut length including jack-stud bearings. A deterministic TypeScript solver turns every opening category into an exact lumber cut list.
1. Typed Opening Allowances Across 7 US Framing Categories
Different US millwork units require completely different rough-opening clearances (especially pocket doors, which frame to 2 * W + 1" width):
export type OpeningType =
| 'prehung_interior'
| 'prehung_exterior'
| 'double_french'
| 'pocket_door'
| 'bifold_bypass'
| 'garage_door'
| 'window';
export type WallRole = 'non_bearing' | 'load_bearing_1story' | 'load_bearing_2story';
export interface RoughOpeningResult {
roWidthIn: number;
roHeightIn: number;
jackStudsTotal: number;
kingStudsTotal: number;
headerSpec: string;
headerCutLengthIn: number;
upperCripples: number;
}
export function computeRoughOpening(
type: OpeningType,
nominalWidthIn: number,
nominalHeightIn: number
): { roWidthIn: number; roHeightIn: number } {
switch (type) {
case 'prehung_interior':
case 'prehung_exterior':
return { roWidthIn: nominalWidthIn + 2, roHeightIn: nominalHeightIn + 2.5 };
case 'double_french':
return { roWidthIn: nominalWidthIn + 2.5, roHeightIn: nominalHeightIn + 2.5 };
case 'pocket_door':
return { roWidthIn: nominalWidthIn * 2 + 1, roHeightIn: nominalHeightIn + 4.5 };
case 'bifold_bypass':
return { roWidthIn: nominalWidthIn + 1.5, roHeightIn: nominalHeightIn + 2 };
case 'garage_door':
return { roWidthIn: nominalWidthIn, roHeightIn: nominalHeightIn };
case 'window':
return { roWidthIn: nominalWidthIn + 0.5, roHeightIn: nominalHeightIn + 0.5 };
}
}
2. Preliminary IRC Table R602.7 Header & Stud Schedule
Once roWidthIn is solved, compute total jack studs (1.5" bearing per stud), total header cut length (roWidthIn + jackStudsTotal * 1.5), SPF #2 header depth for 30 psf ground snow / 28-ft building width preliminary sizing, and 16-inch OC upper cripples:
export function solveOpeningFraming(
type: OpeningType,
nominalWidthIn: number,
nominalHeightIn: number,
role: WallRole
): RoughOpeningResult {
const { roWidthIn, roHeightIn } = computeRoughOpening(type, nominalWidthIn, nominalHeightIn);
const jacksPerSide = role === 'non_bearing' ? 1 : roWidthIn <= 48 ? 1 : roWidthIn <= 72 ? 2 : 3;
const jackStudsTotal = jacksPerSide * 2;
const kingStudsTotal = 2;
const headerCutLengthIn = roWidthIn + jackStudsTotal * 1.5;
const upperCripples = Math.max(0, Math.ceil(roWidthIn / 16) - 1);
let headerSpec = 'Single 2x4 Flat (Non-Bearing)';
if (role === 'load_bearing_1story') {
headerSpec =
roWidthIn <= 38 ? '2-Ply 2x6 SPF #2' :
roWidthIn <= 54 ? '2-Ply 2x8 SPF #2' :
roWidthIn <= 74 ? '2-Ply 2x10 SPF #2' :
roWidthIn <= 90 ? '2-Ply 2x12 SPF #2' : 'Engineered LVL Required';
} else if (role === 'load_bearing_2story') {
headerSpec =
roWidthIn <= 36 ? '2-Ply 2x8 SPF #2' :
roWidthIn <= 50 ? '2-Ply 2x10 SPF #2' :
roWidthIn <= 66 ? '2-Ply 2x12 SPF #2' : 'Engineered LVL Required';
}
return {
roWidthIn,
roHeightIn,
jackStudsTotal,
kingStudsTotal,
headerSpec,
headerCutLengthIn,
upperCripples
};
}
3. Verifying Two Common Framing Traps
- A
36" x 80"pre-hung front entry door in a 1-story load-bearing exterior wall resolves to38" x 82.5"R.O.,2jack studs (1per side),2king studs,2-Ply 2x6 SPF #2, and a41"exact header cut length. - A
32" x 80"pocket door resolves to65" x 84.5"R.O. (not34"!), triggering2jacks per side (4total) and a71"header cut length if framed in a bearing partition.
Interactive Tool & Copyable Workbook
- Run every opening type interactively in the Door & Window Rough Opening & Header Calculator.
- Copy Google Sheet #46: Door/Window R.O., IRC R602.7 Header & Interior Drywall/Trim Takeoff.
- Pair with our Wall Stud & Drywall Framing Takeoff Calculator and Drywall Sheet, Mud & Tape Calculator.
- Draft scaled 2D/3D walls and door swings free in PlanCaliber Browser CAD Studio (
$0watermarked proof PNG;$9Print Pass;$19full 5-sheet PDF +.DXF+.CSVframing takeoff; 14-day instant refunds at PlanCaliber Refunds).
Disclaimer: Preliminary framing and space-planning software math only. Always verify rough openings against the manufacturer spec sheet and confirm structural headers with a licensed engineer and local AHJ.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.