The formula for the work done by a gas is 𝑊=∫𝑓𝑖𝑃𝑑𝑉. What
pressure should be used here?
It is always the external pressure.
I'm asking because I thought you use the gas pressure at every instant
of an expansion.
You do if the process is carried out reversibly (extremely slowly), that is, quasi-statically, so that the gas is always in equilibrium with the surroundings throughout the process. This is not the case in the free expansion.
But if you place a balloon in a vacuum, the external pressure would be
zero, the balloon would expand increasing it's volume, the pressure
inside it would drop, ∫𝑓𝑖𝑛𝑅𝑇𝑉𝑑𝑉 would not be zero and yet the
work done is considered zero (ignoring the tension of the balloon's
If you ignore the tension in the balloon, then you have the equivalent of the gas expanding into a vacuum, like the Joule expansion where a gas expands into a vacuum on the other side of a partition when an opening is created. Then the work is zero since the expansion is against zero external pressure in the evacuated chamber.
Even if you account for the tension in the balloon and wish to determine the work the gas does to expand the balloon, you would need to know exactly how external pressure of the ballon varies with volume in order to evaluate the integral. This is because work is path dependent. In this example you would only know the initial and final equilibrium states, not the path in between.
So, how come in a free expansion 𝑊≠∫𝑓𝑖𝑃𝑑𝑉?
Again, work is zero since the gas expands against zero pressure (if you ignore the balloon tension). If you account for tension, you would need to know how the volume of the gas varies with the tension to evaluate the work integral.
Hope this helps.