Suppose you have to tighten a nut of your bicycle and I tell you to do it by hand, will you be able to do it? No of course not, but what if I give you a wrench with a long lever, then I think you will be able to do it quite easily. The effect is force times distance. The larger the distance from source to the point of application of force, the higher will be the effect.
Now this concept was important before introducing anything about beam as beam resist bending in terms of tension and compression couple:
What happens in I beam is, because the flanges of the beam are the outermost components and they are the stiffest, the force tries to concentrate itself into those stiff flanges. Think of stiffness and force as a relation, higher the stiffness, larger will be the attraction of force into those stiff zones. Which looks like this:
As you can see, the outermost flanges are stressed the most which means that the tension and compression couple is located at the outermost points possible in a beam. This will reduce the amount of stress to resist moment which in turn will reduce the amount of material to resist the moments acting on the beam. So what role does the web play in this whole moment resistance? Shear transfer. Without that web, this will be two individual plates doing nothing, but web is a critical element connecting them to keep the cross section in place and transfer shear.
The above image also confirms with the beam bending theory, that maximum stresses are located at the two ends of the cross section and they are zero at the neutral axis.
So does it mean that only I beam should be used? No. If it is a reinforced concrete member we tend to go for rectangular beams as it will be very difficult to cast I beam. But if it is steel member, we would prefer I section, as they are prefabricated hot tolled steel section. In fact you can make plate girders pretty easily just by combining the plates using welds and bolts.
I section is thus known for efficiency. Least amount of material with maximum possible moment resistance.