Both loans are priced on the same loan amount (home price minus down payment) and held to term, using standard fixed-rate amortization. The monthly figure is principal and interest only. Total interest is the interest accumulated across the full payment schedule, which is the same thing as the monthly payment times the number of payments, minus the loan amount. No extra principal, no points, no refinance.
Property tax, insurance, HOA dues, and maintenance are excluded, because they attach to the home rather than the term: they are identical on both loans and cancel out of the comparison. PMI is excluded too, and it is the one cost that does not cancel exactly. Below 20% down, both loans carry PMI, but the 15-year loan reaches 20% equity sooner and drops it sooner, so leaving PMI out slightly understates the 15-year loan's edge. The PMI calculator prices that separately.
The invest-the-difference model holds the monthly outflow equal on both paths. Both households spend the 15-year payment every month for 30 years, and both own the home free and clear at year 30. The 15-year household puts the whole payment toward the mortgage for 180 months, then invests the whole payment for the remaining 180. The 30-year household makes the smaller mortgage payment and invests the difference every month for all 360. Contributions land at the end of each month and compound monthly at the return you enter, held constant. Real returns are not constant, investment gains are untaxed here, and no mortgage interest deduction is modeled on either side, so read the portfolio figures as a projection rather than a forecast.
If you enter a 30-year rate high enough that the 30-year payment exceeds the 15-year payment, there is no monthly difference left to invest and the equal-outflow comparison no longer holds, so it is not shown.
Related reading: Rent vs Buy With High Interest Rates