In solving field problems, for example problems of electrodynamics, we commonly use the Lagrangian and Hamiltonian formalisms. Hamiltonian formalism of field theory has the advantage over the Lagrangian, which inherently contains a gauge condition. While the gauge condition is introduced ad hoc from some external reasons in the Lagrangian formalism. However, the use of the Hamiltonian formalism in the field theory is difficult due to the non-regularity of the field Lagrangian. We must use such variant of the Lagrangian and the Hamiltonian formalism, which would allow us to work with the field models, in particular, to solve the problem of electrodynamics. We suggest to use the modern differential geometry and the algebraic topology, in particular the theory of fiber bundles, as a mathematical apparatus. This apparatus leads to greater clarity in the understanding of mathematical structures, associated with physical and technical models. The usage the fiber bundles theory allows us to deepen and expand both the Lagrangian and the Hamiltonian formalism. We can detect a wide range of these formalisms. Also we can select the most appropriate formalism. Actually just using the fiber bundles formalism we can adequately solve the problems of the field theory, in particular the problems of electrodynamics.