We develop a sub-Riemannian calculus for hypersurfaces in graded nilpotent Lie groups. We introduce an appropriate geometric framework, such as horizontal Levi-Civita connection, second fundamental form, and horizontal Laplace-Beltrami operator. We analyze the relevant minimal surfaces and prove some basic integration by parts formulas. Using the latter we establish general first and second variation formulas for the horizontal perimeter in the Heisenberg group. Such formulas play a fundamental role in the sub-Riemannian Bernstein problem.