Search engines fanatically guard their “secret sauce” - their incredibly complex (and constantly updating) algorithms for deciding which sites get their top ranking. But behind it all there's a simple theme to how they do it!
Let's go back in time, to - we'll call it the "bad old days" - when things were simpler and SEO tactics were less developed. Or we could call them the “wild West days” - because SEO guys either wore white hats, or black hats! You could get away with some pretty dogdy connivings - “stuffing” the page with the keywords you wanted people to search you on, making some text the same colour as the background to hide sneaky things, and more. But the search engines got wise to this, and started penalizing the “black hat” guys heavily. And they've got wiser and wiser ever since. In 2013, for instance, Google introduced something called "Hummingbird" - a sophisticated algorithm that didn't simply register keywords but was able to trace meanings and contexts. Have you ever entered a phrase in Google and receive suggestions with the same meaning but completely different words? - That's Hummingbird.
But the thing is this. Let's ask ourselves WHY the search engines are continually improving their search methods? Because they want to make SEO more and more difficult? No. There's a much simpler reason. The Search Engines' reputations depend on delivering top-quality results. If you're looking, say, for advice on where to find the best coffee shops in your area and the engine dishes up horrible, 3rd-rate places in the next city, the chances are you won't use that search engine again! Down goes their advertising revenue and everything else.
So the key point is this. Search Engines do everything possible to deliver best quality. The keywords and everything else are but a technicality; a means to an end. The most important thing a site can do is create quality content. Like a bank that only lends money to those who have it in the first place - in precisely the same way, Search Engines will highly rank those websites who would receive the most visitors anyway!
What is SEO? - Search Engine Land
The Moz Guide to SEO
Wikipedia article on SEO
Become an SEO Auditor