The Hamiltonian formulation can be derived from Luke's Lagrangian description by using Leibniz integral rule on the integral of :
with  the value of the velocity potential at the free surface, and  the Hamiltonian density — sum of the kinetic and potential energy density — and related to the Hamiltonian as:
The Hamiltonian density is written in terms of the surface potential using Green's third identity on the kinetic energy:
where  is equal to the normal derivative of  at the free surface. Because of the linearity of the Laplace equation — valid in the fluid interior and depending on the boundary condition at the bed  and free surface  — the normal derivative  is a linear function of the surface potential , but depends non-linear on the surface elevation . This is expressed by the Dirichlet-to-Neumann operator , acting linearly on .
The Hamiltonian density can also be written as:
with  the vertical velocity at the free surface . Also  is a linear function of the surface potential  through the Laplace equation, but  depends non-linear on the surface elevation :
with  operating linear on , but being non-linear in . As a result, the Hamiltonian is a quadratic functional of the surface potential . Also the potential energy part of the Hamiltonian is quadratic. The source of non-linearity in surface gravity waves is through the kinetic energy depending non-linear on the free surface shape .
Further  is not to be mistaken for the horizontal velocity  at the free surface:
Taking the variations of the Lagrangian  with respect to the canonical variables  and  gives:
provided in the fluid interior  satisfies the Laplace equation, , as well as the bottom boundary condition at  and  at the free surface.