NOVELTY - Optimizing production of biogas from at least one feedstock materials, comprises: e.g. (a) determining total elemental nitrogen content in volatile solids or a carbon to nitrogen molar ratio of feedstock materials; (b) determining total elemental nitrogen or total ammonical nitrogen content, or carbon/nitrogen molar ratio of contents of second reactor; and (c) when nitrogen status determination indicates that feedstock is nitrogen rich, or second reactor has below optimum carbon/nitrogen molar ratio, then treating feed stock with ammonifying microbial species to produce ammonia digestate.    USE - The process is useful for optimizing production of biogas from feed stock materials (claimed) and for removing ammonia from nitrogen rich feed stock.    ADVANTAGE - The process: optimizes the production of bio gas by utilizing two-phase anaerobic digestion of feed stock; and facilitates the recirculation of biogasification reject water into the process.    DETAILED DESCRIPTION - Optimizing production of biogas from at least one feedstock materials, conducted in at least a second reactor, comprises: (a) determining total elemental nitrogen content in volatile solids or a carbon to nitrogen molar ratio of the feedstock materials; (b) determining total elemental nitrogen content or total ammonical nitrogen content or carbon/nitrogen molar ratio of the contents of the second reactor, where the feedstock material is nitrogen rich when the carbon/nitrogen molar ratio of the feedstock material is below 15, or the total elemental nitrogen content in volatile solids of the feed-stock material is above 40 g nitrogen/kilogram volatile solids, and the feedstock material is carbon rich when the carbon/nitrogen molar ratio of the feedstock material is above 15, or the total elemental nitrogen content in volatile solids of the feedstock material is below 40 g nitrogen/kg of volatile solids, the nitrogen status in the second reactor is optimal when the carbon/nitrogen molar ratio in reactor contents is 5-12, or the amount of total ammonical nitrogen in reactor contents is 0.1-2.5 g/l, or the amount of total elemental nitrogen in reactor contents is 0.3-2.8 g/l; (c) when the nitrogen status determination in step (a) or step (b) indicates that the feedstock is nitrogen rich, or that the second reactor has a below optimum carbon/nitrogen molar ratio or an above optimum content of total ammonical or elemental nitrogen, treating the nitrogen rich feed-stock in a first reactor with at least one ammonifying microbial species to produce an ammonia digestate, where an ammonia digestate is a digestate originating from the first reactor, where the feedstock has been ammonified until preferably more than 50% of the total elemental nitrogen in the feedstock is converted to ammonia; (d) delivering the ammonia digestate from the first reactor to a nitrogen removal system; (e) treating the ammonia digestate in the nitrogen removal system to produce an ammonia-reduced digestate, where an ammonia-reduced digestate is an ammonia digestate that has passed through the nitrogen removal system to achieve removal of at least 80% of ammonia nitrogen; (f) delivering the ammonia-reduced digestate from the nitrogen removal system to the second reactor; (g) when the nitrogen status determination in step (a) indicates that the feedstock is carbon rich, delivering carbon rich feedstock directly to the second reactor; and (h) when the nitrogen status determination in step (b) indicates that the second reactor has an above optimum carbon/nitrogen molar ratio or a below optimum content of total ammonical or elemental nitrogen, delivering nitrogen rich feed stock directly to the second reactor. The process further comprises (i) producing biogas from the delivered feed stock with at least one methanogenic microbial species in the second reactor; and (j) determining nitrogen status of the ammonia-reduced digestate after nitrogen removal and controlling efficiency of the nitrogen removal system and flow of ammonia-reduced digestate into the second reactor. An INDEPENDENT CLAIM is also included for a system for optimizing production of biogas from a feed stock, comprising: a first reactor for treating feed stock to carry out ammonification to generate an ammonia digestate; a system for nitrogen removal to generate an ammonia-reduced digestate from ammonia digestate; a second reactor for producing biogas from the ammonia-reduced digestate, means for delivering various types of feed stock to the first reactor separately; means for delivering the ammonia digestate from the first reactor to the system for nitrogen removal; means for delivering the ammonia-reduced digestate from the system for nitrogen removal to the second reactor; and means for delivering feed stock or ammonia nitrogen directly to the second reactor.