Adam Smith stated that when individuals pursue their self-interest they are motivated to act in an efficient manner and this leads to an outcome that is also positive for the society as a whole.
For example, a baker does not make bread motivated by the desire of feeding hungry people, but due to the need of earning money for a living. Although the inner motivation is totally selfish, he is simultaneously contributing with the community and break is now available in the market. The more efficiently the baker is when producing his bread, the lower the production costs and the higher his earnings would be. Again, this is a selfish motive, but lower costs also lead to lower market price of bread and consumers are benefited from this as the pay less.