The Bernoulli problem is rephrased into a shape optimization problem. In particular, the cost function, which turns out to be a constitutive law gap functional, is borrowed from inverse problem formulations. The shape derivative of the cost functional is explicitly determined. The gradient information is combined with the level set method in a steepest descent algorithm to solve the shape optimization problem. The efficiency of this approach is illustrated by numerical results for both interior and exterior Bernoulli problems.