The mutualistic association between leguminous plants and endosymbiotic rhizobial bacteria is a paradigmatic example of a symbiosis driven by metabolic exchanges. Here, we report the reconstruction and modelling of a genome-scale metabolic network of Medicago truncatula (plant) nodulated by Sinorhizobium meliloti (bacterium). The reconstructed nodule tissue contains five spatially distinct developmental zones and encompasses the metabolism of both the plant and the bacterium. Flux balance analysis (FBA) suggests that the metabolic costs associated with symbiotic nitrogen fixation are primarily related to supporting nitrogenase activity, and increasing N2-fixation efficiency is associated with diminishing returns in terms of plant growth. Our analyses support that differentiating bacteroids have access to sugars as major carbon sources, ammonium is the main nitrogen export product of N2-fixing bacteria, and N2 fixation depends on proton transfer from the plant cytoplasm to the bacteria through acidification of the peribacteroid space. We expect that our model, called 'Virtual Nodule Environment' (ViNE), will contribute to a better understanding of the functioning of legume nodules, and may guide experimental studies and engineering of symbiotic nitrogen fixation.