Compressible flows over cavities with a series value of length-to-depth ratio (L/D) were investigated experimentally, with the objective being to elucidate the mechanism of the transition of types of cavity flows as their L/D increases or decreases. For open-type cavity flows, the freedom of backflow inside the cavity is found to be crucial in smoothing out adverse pressure gradient. The spreading of the shear layer and its gradual approach toward the cavity floor as L/D increases tend to suppress the freedom of backflow, causing the cavity flow to change from the open-type to the transitional-type. For closed-type cavity flows, the finite thickness of the upstream boundary layer leads to the presence of three kinds of characteristic lengths that correspond to the recirculation region, the deflection of the main flow and the recovery or the abrupt rise of the pressure, respectively. The compression fans at the foot of the impingement and the exit shock waves will approach each other well in advance of the possible merge of the vertices of the conventionally defined separation and recompression wakes. As the L/D of a closed cavity decreases, the reattached boundary layer on the mid-portion of the cavity floor will have less developing distance, thus it will be more susceptible to adverse pressure gradient and prone to separation. For the present two-dimensional cavity models, the critical values of L/D were found to be about 10 and 14 for the transition of cavity flows from the open-to the transitional-type and from the transitionalto the closed-type, respectively. The sum of the pressure lengths at the front and rear wakes agrees remarkably well with the second critical L/D.