The balancing of inverted pendulum along a vertical position by applying force to the cart is a typical problem in the area of automatic control. Its popularity derives from the fact that it is unstable without control. This article describes creation of the mathematical model, analyzing its behavior and state space controller design for subsequent use in programmable logic controller. Mathematical model was created using the Lagrange equations of second kind. After linearization in working point state-space model and transfer function were derived. Finally controller was designed and simulated in MATLAB Simulink.