The paper proposes a methodology for calculating lateral buckling of beams of variable rectangular cross section based on the energy approach. The technique is considered on the example of a cantilever beam of variable width with two sections under the action of a concentrated force. The twist angle function was set in the form of a trigonometric series. As a result, the problem is reduced to a generalized secular equation.