The phenomenon of surface tension arises due to the cohesive forces between the molecules of a liquid. The net cohesive force on the liquid molecules within the surface film differs from that on molecules deep in the interior of the liquid.
Consider three molecules of a liquid : A molecule A well inside the liquid, and molecules B and C lying within the surface film, shown in figure. The figure also shows their spheres of influence of radius R.

Three molecules of a liquid with their spheres of influence
(1) The sphere of influence of molecule A is entirely inside the liquid and the molecule is surrounded by its nearest neighbours on all sides. Hence, molecule A is equally attracted from all sides, so that the resultant cohesive force acting on it is zero. Hence, it is free to move anywhere within the liquid.
(2) For molecule B, a part of its sphere of influence is outside the liquid surface. This part contains air molecules whose number is negligible compared to the number of molecules in an equal volume of the liquid. Therefore, molecule B experiences a net cohesive force downward.
(3) For molecule C, the upper half of its sphere of influence is outside the liquid surface. Therefore, the resultant cohesive force on molecule C in the downward direction is maximum.
(4) Thus, all molecules lying within a surface film of thickness equal to R experience a net cohesive force directed into the liquid.
(5) The surface area is proportional to the number of molecules on the surface. To increase the surface area, molecules must be brought to the surface from within the liquid. For this, work must be done against the cohesive forces. This work is stored in the liquid surface in the form of potential energy. With a tendency to have minimum potential energy, the liquid tries to reduce the number of molecules on the surface so as to have minimum surface area. This is why the surface of a liquid behaves like a stressed elastic membrane.