"u" vs "n" orientation of channel profiles: why difference in strength?

For example, metal tape measures can be extended and stay straight when in a "u" orientation, but collapse the other way round.

I presume the same phenomenon is why metal shelving has sheet metal on top, and flanges on the bottom rather than the top.

Why is this?

I'm guessing: it's because of the direction of compression/tension, and buckling. Since a long piece of material being compressed is more likely to buckle than a short piece. In one orientation, the buckling can only happen when the walls buckle across their height but in the other orientation, the compression acts across the entire length of the channel?

Both a common-sense approach, and a mathematical approach are welcome; I assume formulas are well established, using "moment of inertia" values for beam profiles or similar.

Since the stress at a given fiber at a distance $y$ from the centroid is equal to $$\sigma = \dfrac{My}{I}$$ in bending, this means that the stresses in the web will be lower than the stresses at the ends of the flanges.