The object of the invention is a process of biogas and hydrogen production. The method of biogas production in the methane fermentation process is characterized in that it is performed in three stages, wherein each stage runs in a separate chamber and the chambers are connected to each other and form a linear system. Moreover, in the first stage, the substrate is mixed, homogenized and therein the batch is formed, which is vaccinated with a bacterial inoculum. The bacterial inoculum is derived from the digestate obtained in the process and contains bacteria of hydrolysis, acidogenesis and acetaneogenesis and prior to vaccination is subjected to aerobic treatment. The duration of the first stage is between 90 and 180 minutes and the process is carried out in the inoculum and mixing chamber (1). Subsequently, in the second stage, the batch obtained in the first stage is fed with high dynamics to the acid-hydrogen fermentation chamber (2) and the process runs at pH 2.5 to 4.5 and overpressure between 100 and 20