Spray foam arrives as two liquid components that are heated, pressurized and combined at the tip of the applicator gun. The reaction happens on contact with the surface, and the material expands within seconds, flowing into framing cavities, around wiring and plumbing, and into the small irregular gaps that pre-cut batts cannot follow. As it cures it bonds to the substrate and becomes part of the assembly rather than something stuffed into it.
That expansion is what makes the difference in a Montana winter. Heat does not just conduct through a wall, it leaks through it, and a wall full of insulation with air moving around the edges performs far below its rated R-value. Spray foam removes the leakage path.