<p>With the sole exception of the Avatar, bending can be either inherited from families with benders, bestowed upon by Energybenders like the Avatar or Lion Turtles. According to people like Yue, Toph, Aang, Zuko and others, before the revelation of the Lion Turtles, people learned to bend the elements from sources like the Moon, Badger Moles, Sky Bison and Dragons.
It's also due to a person's spirituality; the higher their spiritual connection to their element is, the higher the chances of having the ability to bend the element are.
And Noatok and Tarlok, the sons of Yakone, prove that bending can be inherited from one that had their bending removed.
</p>