SEO works by optimizing a website's content, structure, and technical elements to make it more appealing to search engines. The key factors that affect search engine rankings include website content, website structure, backlinks, and technical elements such as page speed and mobile-friendliness.