Link Popularity algorithms are extremely complex and I will not be going into full detail on the nuanced bits of mathematics involved. This article instead aims to provide a solid basic understand of how link popularity works and parts are simplified for easier understanding.
The most important thing you must understand when working with link popularity is that every page is treated as a separate entity. What this means is that internal links, that is links between the pages of your site, do count. In fact search engines make no distinction between those links and links from other outside pages. This is something that many people get hung up on, they do not understand why search engines would count internal links. What they don't realize is that there is really no way to tell if a link is from an internal or external page, since some sites span multiple domains and multiple sites can exist on one domain. As such optimizing your own internal site links can be as important as gaining new links from other sites. For more on optimizing your internal site links see this article: Site Architecture: Optimizing your Internal Links.
Another issue that some people get hung up on is that they think that reciprocal links can hurt you, meaning if you link to a page that links to you then you will be punished. This is not entirely true. Search Engines actively seek out artificial linking schemes and some link exchanges can be seen as such, however they usually just devalue the links rather than penalize the sites involved. So while link exchanges are good, they should be entered into with some trepidation, as will be discussed later.
Now link popularity is not a purely quantitative measurement. Instead the quality of links often counts more than the sheer number of links. Quality plays a role in two different ways. The first is that the context of your link is important. If you want to rank high on certain keywords then you need the pages that link to you to be related to those keywords. If the pages linking to you are not related to your site's keywords then they will do little to raise your ranking for those keywords. Also, more specifically, the text directly surrounding your link, or the text within the link itself, as well as any nearby headers or the page title can all influence what the search engine sees as the context of your link. If you read my article on choosing the right domain name you might remember that having a keyword rich domain name or site title can again help your rank. Since people will link to you using your domain name or site title, having keywords in them, and thus in your link text, can help with link popularity in this manner. In fact having people link to you using your keywords is extremely important and beneficial, and of course using keywords in your own internal links helps as well. For instance it is common to link to your home page using the word "Home." Don't do this if you can avoid it, instead use your keywords in the link. Sure it may look a little funny but the benefit will be immense. I have a page that once got ranked #1 on AltaVista (yes, I did just date myself) on a search that returned over 8 million results and it was ranked higher than some rather large corporate entities such as NASDAQ. The reason? I linked to this page on every of nearly 10,000 pages on my site using my desired keywords. The text inside the links that point to your site is extremely important and a big reason why you need keywords in your domain and site name. Even a link from a completely unrelated site will still help if your keywords are in the anchor text.