We investigated how the magnetic field in solar active regions (ARs) controls flare activity, i.e., whether a confined or eruptive flare occurs. We analyzed 44 flares of GOES class M5.0 and larger that occurred during 2011-2015. We used 3D potential magnetic field models to study their location (using the flare distance from the flux-weighted AR center d FC ) and the strength of the magnetic field in the corona above (via decay index n and flux ratio). We also present a first systematic study of the orientation of the coronal magnetic field, using the orientation ϕ of the flare-relevant polarity inversion line as a measure. We analyzed all quantities with respect to the size of the underlying dipole field, characterized by the distance between the opposite-polarity centers, In confined events the flare-relevant field adjusts its orientation quickly to that of the underlying dipole with height (∆ϕ 40• until the apex of the dipole field), in contrast to eruptive events where it changes more slowly with height. The critical height for torus instability, h crit = h(n = 1.5), discriminates best between confined (h crit 40 Mm) and eruptive flares (h crit 40 Mm). It discriminates better than ∆ϕ, implying that the decay of the confining field plays a stronger role than its orientation at different heights.