Dev.to WebDev 🛠 Dev 👁 0 📖 5 min read

Encoding IRC R311.7 Stair Stringer Headroom & IRC R310.2 Egress Window Geometry in Pure TypeScript

Two residential framing mistakes account for an outsized share of failed US basement and remodel inspections: Short stair-well floor cutouts, caused by computing headroom against the upper finished floor instead of su

Two residential framing mistakes account for an outsized share of failed US basement and remodel inspections:

  1. Short stair-well floor cutouts, caused by computing headroom against the upper finished floor instead of subtracting the 10"–14" floor joist assembly depth at the header soffit.
  2. Non-compliant basement egress windows, caused by assuming a 36" x 48" rough opening passes the IRC 5.7 sq ft clear-opening rule when a double-hung sash actually opens less than half its height.

When we built the interactive IRC R311.7 Stair Stringer Calculator and IRC R310.2 Basement Egress Window Calculator inside PlanCaliber, we encoded both solvers in zero-dependency TypeScript (src/lib/cad/calculators.ts). Here is the exact math — and the subtle floating-point and framing edge cases worth getting right.

1. Formatting Exact 1/8" Imperial Measurements Without Rollover Bugs

US framers lay out stringers and rough openings to the nearest 1/8". A naive formatter that rounds inches and fractions independently produces broken strings like 7 8/8" or 8'-12". Converting the entire magnitude into integer eighths first, then dividing by 96 (12 * 8) for feet and 8 for whole inches, guarantees atomic carry-over:

export function formatFeetInchesEighths(inches: number): string {
  if (!Number.isFinite(inches)) return `0'-0"`;
  const sign = inches < 0 ? '-' : '';
  const totalEighths = Math.round(Math.abs(inches) * 8);
  const feet = Math.floor(totalEighths / 96);
  const remEighths = totalEighths % 96;
  const wholeInches = Math.floor(remEighths / 8);
  const fracEighths = remEighths % 8;

  if (fracEighths === 0) return `${sign}${feet}'-${wholeInches}"`;
  return `${sign}${feet}'-${wholeInches} ${eighthFractionLabel(fracEighths)}"`;
}

Any value like 95.96" rounds cleanly to 768 eighths -> 8'-0", never 7'-12" or 7'-11 8/8".

2. Stair Stringers: Why Forgetting upperAssemblyIn Breaks Headroom

Under IRC R311.7.5.1, residential stairs have a maximum riser height of 7.75" (7-3/4"), a minimum tread run of 10" (R311.7.5.2), a minimum clear width of 36" (R311.7.1), and a minimum vertical headroom of 80" (6'-8", R311.7.2) measured vertically from the sloped tread-nosing plane up to the ceiling or stairwell header soffit.

The trap: totalRiseIn is measured finished floor to finished floor (lowerCeilingTotalIn + upperAssemblyIn), where upperAssemblyIn includes the upper floor joists (e.g., 9-1/4" 2x10 or 11-7/8" I-joists), subfloor, finish flooring, and lower ceiling drywall (~11.5" to 14" total).

At the edge of the stairwell header opening, the vertical distance from the upper finished floor down to the sloped nosing line must equal minHeadroomIn + upperAssemblyIn, not just minHeadroomIn:

const totalRiseIn = lowerCeilingTotalIn + upperAssemblyIn;
// Epsilon prevents floating-point exact multiples of 7.75" (e.g. 108.50000000000001")
// from jumping to an unnecessary extra riser.
const optimalRiserCount = Math.max(2, Math.ceil((totalRiseIn - 1e-6) / 7.75));
const treadCount = Math.max(1, riserCount - 1);
const unitRiserIn = totalRiseIn / riserCount;
const totalRunIn = treadCount * treadRunIn;

// IRC R311.7.2: vertical drop from upper finished floor to nosing line at header face
const verticalDropAtHeaderIn = minHeadroomIn + upperAssemblyIn;
const minCutoutLengthIn = (verticalDropAtHeaderIn / unitRiserIn) * treadRunIn;
const roughFramingCutoutIn = minCutoutLengthIn + 1.5;

const stringerLengthIn = Math.hypot(totalRiseIn, totalRunIn);
const slopeDeg = (Math.atan2(unitRiserIn, treadRunIn) * 180) / Math.PI;

Work through a concrete 8'-0" (96") basement ceiling with a 12" upper floor assembly (totalRiseIn = 108") and 10" treads:

  • optimalRiserCount = Math.ceil((108 - 1e-6) / 7.75) = 14 risers (13 treads)
  • unitRiserIn = 108 / 14 = 7.714" (7 3/4" -> PASS <= 7.75")
  • totalRunIn = 13 * 10 = 130" (10'-10")
  • verticalDropAtHeaderIn = 80 + 12 = 92"
  • minCutoutLengthIn = (92 / 7.714) * 10 = 119.26" (9'-11 1/4"), plus 1.5" rough framing allowance -> 10'-0 3/4"
  • stringerLengthIn = Math.hypot(108, 130) = 169.01" (14'-1") -> requires 16' stock 2x12 lumber (stockLengthsFt.find(ft => ft >= neededFt))!
  • For a 36" wide stair, Math.max(3, Math.ceil(clearWidthIn / 16) + 1) = 4 stringers at 16" OC spacing (or 3 on standard 12"–16" spans when using 36" clear width inside framing — our conservative formula guarantees solid mid-tread stiffness).

Notice what happens if a calculator forgets upperAssemblyIn: (80 / 7.714) * 10 = 103.7" — 15.6" too short, creating an immediate 68" headroom collision right under the stairwell header.

3. IRC R310.2 Basement Egress Windows: Rough Opening vs. Net Clear Opening

A finished basement bedroom or sleeping room requires an Emergency Escape and Rescue Opening (IRC R310.2) satisfying four simultaneous thresholds:

  1. Net Clear Area: >= 5.7 sq ft (820.8 sq in) for basements and upper floors, or >= 5.0 sq ft (720 sq in) at grade floor.
  2. Minimum Net Clear Width: >= 20".
  3. Minimum Net Clear Height: >= 24".
  4. Maximum Finished Sill Height: <= 44" above the finished floor.

Note the trap: 20" x 24" is only 480 sq in (3.33 sq ft)! Meeting both minimum dimensions does not satisfy the 5.7 sq ft area check — you need at least 20" x 41.1" or 34.2" x 24".

Even trickier, homeowners and drafters usually know a window's rough opening (rw x rh), not its sash-open clear daylight. Each operator type loses a different share of the rough opening to jambs, sash stiles, and fixed panes:

export function estimateNetClearOpening(
  windowType: 'casement' | 'double_hung' | 'slider',
  roughWidthIn: number,
  roughHeightIn: number
): { widthIn: number; heightIn: number } {
  const rw = clampVal(roughWidthIn, 12, 120);
  const rh = clampVal(roughHeightIn, 12, 120);

  if (windowType === 'casement') {
    return {
      widthIn: Math.max(0, Number((rw - 6).toFixed(2))),
      heightIn: Math.max(0, Number((rh - 5).toFixed(2)))
    };
  }
  if (windowType === 'double_hung') {
    return {
      widthIn: Math.max(0, Number((rw - 4.5).toFixed(2))),
      heightIn: Math.max(0, Number((rh / 2 - 4.5).toFixed(2)))
    };
  }
  // Horizontal slider: only half the width opens cleanly
  return {
    widthIn: Math.max(0, Number((rw / 2 - 4).toFixed(2))),
    heightIn: Math.max(0, Number((rh - 4.5).toFixed(2)))
  };
}

Compare the exact same 36" x 48" rough opening across all three window types:

  • Double-Hung (36" x 48"): 31.5" W x 19.5" H = 4.27 sq ft -> FAILS both min height (19.5" < 24") and min area (4.27 < 5.7 sq ft).
  • Horizontal Slider (36" x 48"): 14.0" W x 43.5" H = 4.23 sq ft -> FAILS both min width (14.0" < 20") and min area.
  • Casement (36" x 48"): 30.0" W x 43.0" H = 8.96 sq ft -> PASSES every IRC R310.2 check with generous margin.

That single function explains why basement foundation cutouts almost universally specify in-swing or out-swing casement egress windows (or oversized 48" x 48"+ sliders) instead of standard double-hungs.

4. Window Well Area, Projection & Automatic Ladder Trigger (IRC R310.4)

When a basement egress window sits below grade, IRC R310.4 adds three checks on the exterior window well:

const wellAreaSqFt = (wellWidthIn * wellProjectionIn) / 144;
const wellAreaPass = wellAreaSqFt >= 9.0 - 1e-6;
const wellProjectionPass = wellProjectionIn >= 36 - 1e-6;
const ladderRequired = input.includeWindowWell && wellDepthIn > 44 + 1e-6;
const wellPass = !input.includeWindowWell || (wellAreaPass && wellProjectionPass);

Whenever wellDepthIn > 44", the solver automatically flags ladderRequired = true, reminding the planner to specify a permanently affixed ladder or steps (>= 12" wide, >= 3" off wall, <= 18" rung spacing) that do not obstruct the casement sash swing.

Try the Interactive Calculators & Basement / ADU Floor Plan Studio

Both solvers run live in your browser with instant SVG framing diagrams and one-click transfer into PlanCaliber's 2D/3D CAD studio:

Drafting in 2D, inspecting live 3D cutaway views, and running clearance checks are free in your browser with no account required. When you want unwatermarked 1/4"=1'-0" vector PDFs (A-101 + M-101), 2400px PNG, and SVG, the one-time Clean Print & Share Pass is $9 (or $19 once for the full 5-sheet CAD package including layered AutoCAD R12 .DXF, 3D .OBJ, and framing/drywall .CSV), backed by a 14-day instant refund policy. (PlanCaliber generates preliminary space-planning drawings and code-reference estimates — always verify exact manufacturer egress specs and local AHJ amendments with a licensed professional or building inspector before cutting foundation walls or framing.)

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.