Variation among genes codes for different phenotypes in a population. Individuals that have a phenotype that is better suited to their environment are more able to survive and reproduce, and therefore, have a higher chance of passing on their genes to individuals. Natural selection is the process by which these individuals or these genes are "selected for" as they offer a fitness advantage to an individual. Over time, a higher proportion of individuals in the population have a copy of this gene, leading most of the population evolve to express the adaptive phenotype.
An example of this is peppered vs. black moths. Before the industrial revolution, white lichens (a type of fungal species) lived on trees, giving tree trunks a "peppered" colour pattern due to the white lichens and gaps of dark tree trunk. Moths at that time evolved to be peppered colour too, so that they could blend in with the tree and hide from predators like birds. During the industrial revolution, pollution killed the lichens and dark soot covered the trees, making them black in colour. The moths that were peppered could no longer disguise themselves, and were eaten by predators. However, some moths were black. These moths were able to survive and reproduce, passing on the gene for black colour to their offspring. Over time, almost all of the moths in the population had evolved to be black instead of peppered through natural selection.