EDIT in reply to query in comment.

One way of stating Archimedes’ law (principle) is that the upthrust equals the weight of fluid displaced.

As a simple example, if a sphere of volume 0.1m³ is immersed in water:

volume of displaced water is V = 0.1m³;

mass of displaced water is m= ρV = 1000x0.1 = 100kg (using density ρ =1000kg/m³);

weight of displaced water = mg = 100x9.8 =9800N(using g = 9.8m/s²).

So there is an upthrust of U = 9800N (upwards) and the resultant force on the sphere is the vector-sum of this and the sphere’s weight.

The above calculation assumes the density of water is constant. (It also assumes g is constant, but that’s not usually an issue.)

If the density is not constant, in general it will be a function of position and we must find the mass of fuid displaced (m) in a different way. We do this using calculus. If the density of the fluid as a function of position is ρ(x,y,z) in the absence of the object, then we must perform a volume integral:

m = ∫∫∫ρ.dx.dy.dz where the integral is within the region bounded by the immersed object’s surface.

That might not make sense unless you know some calculus, but I hope it helps.

END EDIT

Valid for all fluids. E.g. air in compressible and a helium balloon rises when released because the upthrust = weight of displaced air (and upthrust is greater than the balloon's weight).

However, in situations where there density varies (because of variations in pressure and/or temperature), the calculation of the weight of displaced fluuid is complicated.