how plant roots take up nitrogen
It isn't the peas and beans that are making the fertilizer though, it's the nitrogen fixing bacteria, various Rhizobium, that actually do the nitrogen fixing. These bacteria colonize the roots of their preferred plant partner. From their homes in the plant roots they take nitrogen from the air and convert it into ammonia, a form of nitrogen that plants can use. For this valuable service the legumes feed the bacteria a steady diet of plant sugars. Your soil may already have several varieties of rhizobia present that live on from year to year.