The stability characteristics of compressible spanwise-periodic open-cavity flows are investigated with direct numerical simulation (DNS) and biglobal stability analysis for rectangular cavities with aspect ratios of L/D = 2 and 6. This study examines the behavior of instabilities with respect to stable and unstable steady states in the laminar regimes for subsonic as well as transonic conditions where compressibility plays an important role. It is observed that an increase in Mach number destabilizes the flow in the subsonic regime and stabilizes the flow in the transonic regime. Biglobal stability analysis for spanwise-periodic flows over rectangular cavities with large aspect ratio is closely examined in this study due to its importance in aerodynamic applications. Moreover, biglobal stability analysis is conducted to extract 2D and 3D eigenmodes for prescribed spanwise wavelengths λ/D about the 2D steady state. The properties of 2D eigenmodes agree well with those observed in the 2D nonlinear simulations. In the analysis of 3D eigenmodes, it is found that an increase of Mach number stabilizes dominant 3D eigenmodes. For a short cavity with L/D = 2, the 3D eigenmodes primarily stem from centrifugal instabilities. For a long cavity with L/D = 6, other types of eigenmodes appear whose structures extend from the aft-region to the mid-region of the cavity, in addition to the centrifugal instability mode located in the rear part of the cavity. A selected number of 3D DNS are performed at M ∞ = 0.6 for cavities with L/D = 2 and 6. For L/D = 2, the properties of 3D structures present in the 3D nonlinear flow correspond closely to those obtained from linear stability analysis. However, for L/D = 6, the 3D eigenmodes cannot be clearly observed in the 3D DNS, due to the strong nonlinearity that develops over the length of the cavity. In addition, it is noted that three-dimensionality in the flow helps alleviate violent oscillations for the long cavity. The analysis performed in this paper can provide valuable insights for designing effective flow control strategies to suppress undesirable aerodynamic and pressure fluctuations in compressible open-cavity flows.