In this paper we give a simple proof that when the particle number is conserved, the Lagrangian of a barotropic perfect fluid is Lm = −ρ c 2 + P (ρ)/ρ 2 dρ , where ρ is the rest mass density and P (ρ) is the pressure. To prove this result nor additional fields neither Lagrange multipliers are needed. Besides, the result is applicable to a wide range of theories of gravitation. The only assumptions used in the derivation are: 1) the matter part of the Lagrangian does not depend on the derivatives of the metric, and 2) the particle number of the fluid is conserved (∇σ(ρu σ ) = 0).