Gas Spheres
For a gaseous body like the sun, hydrostatic equilibrium occurs when gravity matches the internal pressure of the gasses making up the body. A body is in hydrostatic equilibrium when, on average, it is neither expanding nor contracting -- for example, a solar flare may push material out from the sun, but in general its shape and size remain constant.
Gravity
Gravity is a property of mass. Within a body, the gravitational force at a given point is related to the amount of mass closer to the body's center than the given point. That is, mass farther from the center does not add to the gravitational force at that point. Mathematically, gravitational acceleration is expressed -G * M(r) / r^2, with "r" being the radius, or distance from the body's center, "M(r)" representing the amount of mass within that radius, and "G" as Newton's gravitational constant.
Pressure
To calculate pressure, you need to make an assumption about the behavior of the material composing the planet. The simplest assumption is the body is composed of incompressible fluid; that is, the density, ρ, does not change throughout. A more complex assumption, though, would be the body is composed of material following the ideal gas law, where density is a function of pressure and temperature.
The Equation of Hydrostatic Equilibrium
The differential equation for hydrostatic equilibrium says an infinitesimal pressure difference is related to an infinitesimal change in radius. The equation relating the two is: dPressure = - [G * M (r) * ρ (r)/ r^2 ] dr.
If you assume the body has a constant, uniform density, ρ, then the mass of a sphere of radius r will be (4 / 3) * pi * ρ * r^3. The gravitational acceleration will be - (4 / 3) * G * pi * ρ * r, and the differential equation relating pressure and radius becomes: dPressure = -[(4/3)*G*ρ^2*r] dr.
The Appearance of the Solution
The solution to the equation of hydrostatic equilibrium for a body with constant density is a sphere with maximum pressure at its center but falling to zero at the surface along a parabolic trajectory. Mathematically, the pressure at a radius r is Pressure(r) = Pressure(center) *(1 - (r/R)^2), with "R" is the overall radius of the body. The form of the solution will change if different assumptions are made about the material, but they will all share one key characteristic: the pressure is only a function of r, the distance from the center of the body.
Shapes
In a body at hydrostatic equilibrium, the forces acting on the material will only depend upon the radius, as described in the previous section. Because of this, an ideal body at hydrostatic equilibrium will be a perfect sphere. If any section is moved out of balance, the forces push it right back into balance. And because the forces are in balance at the radius r, the balance point is in a spherical shape.
Planets and Hydrostatic Equilibrium
In 2006, the International Astronomical Union adopted a definition for "planet" including the condition that the body must assume a "hydrostatic equilibrium (nearly round) shape." The intention of this definition is to separate bodies with gravitational forces not strong enough to overcome the structural forces creating its features. That is, a rough, jagged object would not qualify. The problem is the IAU didn't define how round is round. So there's really no way to calculate whether a rocky planet like the Earth is in hydrostatic equilibrium. Astronomers just look at bodies in the solar system and decide if they're "round enough."