There are over 200 factors which determine where your website ranks on any particular search engine at any particular time. These factors are constantly changing and yet they boil down to two things: Relevancy and Popularity.
Search engines work by indexing websites on the Internet and using the content and other attributes on those sites to display results to those searching. The ranking of a website in search engine result pages (SERPs) is usually calculated by looking at 2 main factors:
A) On-site | Relevancy of content on the site:
The relevancy of the content is usually judged by such factors as keyword density of certain keywords or phrases a user is searching on, the page title, name of images, number of pages of the site with relevant content, how recent the content is, keywords in the headings and many other factors.
B) Off-site | Popularity of the website:
There are many factors which influence search engine's calculation of popularity, but it is typically calculated by looking at the number and trustworthiness of links to a website. Normally quality is more important than quantity of incoming links.
The two above factors contribute to what search engines call the 'algorithm' to judge website relevancy. These days it is also a function of “who you know” rather than “what you know” as Google et al. are placing more and more importance on the discussions customers are having about your business on Facebook and other social websites. Search engine marketing and social media marketing are becoming more integrated every day.