One of the main problems in modern economy is to construct an efficient organizational hierarchy allowing to control the firm with minimal cost. This paper describes the mathematical model of optimal hierarchies in firms. Optimal hierarchies for several classes of cost functions are obtained. Particularly, sufficient conditions for tree optimality, 2?hierarchy (any manager has two immediate subordinates) optimality and two-tier hierarchy optimality are defined.