Background
Evolution is a process by which populations (i.e., a group of organisms of one species) change. Evolution may be adaptive, that is to say, it may result in populations that are better suited to their environment or more fit; alternatively, it may be neutral or maladaptive. Often when we think about populations evolving, we are interested in adaptive evolution, the process by which populations change to become better suited to their environment.
A common set of steps to result in adaptive evolution is as follows (we'll unpack these steps in a bit):
1) Heritable variability for a trait exists in the population.
2) A selective pressure exists in the environment that leads some individuals in the population to be more fit.
3) The more fit individuals reproduce more successfully and/or faster, and eventually, the population becomes dominated by the descendants of the individuals with the higher fitness.
Example: How did the giraffe get a long neck?
Let's take an example that we often imagine when thinking about evolution -- how did the giraffe get such a long neck? Let's go through the steps we might hypothesize occurred in the past that result in us currently observing populations of giraffes with long necks.
1) There was an ancestral population of giraffe-like organisms that had, on average, shorter necks than the population we see today. However, within this population, there was variation for the trait of interest (i.e., some giraffes had longer necks than others). Importantly, this variability was heritable, which means that if a mama and/or papa giraffe had a long neck, their offspring (i.e., kiddos) were relatively likely to have long necks, too. At a molecular level, we suspect the parental giraffe(s) had one or more genes that caused or predisposed them to have long necks. These genes were the heritable units that could be passed down from parent to child.
2) The giraffes were nourished by eating leaves on trees. Unfortunately, there weren't always enough leaves within reach to go around. Sometimes, giraffes could not get enough food. Because of this, they were less healthy, and they were more likely to die young before having very many offspring, and their offspring were less healthy. However, giraffes with longer necks were able to reach leaves that none of the other giraffes could get, so they were generally healthier and had more offspring. Their offspring were also likely to have long necks, so they in turn thrived and had more offspring.
3) Eventually, the gene for tall necks permeated the entire giraffe population, until all giraffes had long necks, and they had access to a wider range of food (i.e., food that was low to the ground as well as high up in trees).
A few notes about this example:
1) Although the gene for long necks became the only 'neck length' gene in the population, other genes from short-necked giraffes may persist. This is the beauty of sexual reproduction -- there is genetic exchange, or recombination, between chromosomes (i.e., linked sets of genes) from two different parents.
2) An alternative hypothesis could be that the fact that giraffes have long necks is not adaptive, but rather, the result of a more random process such as genetic drift. If this were the case, we would still begin with heritable variability, however, instead of some organisms being more fit than others, there would be an event that randomly only allowed long-necked giraffes to survive and/or reproduce. For example, the population could have undergone a bottleneck, in which only a few individuals survive after, for example, an earthquake. When there are only a few organisms, it is likely that the distribution of traits in the small population will not be the same as the distribution in the population before the bottleneck event occurred. If, by chance, only long-necked giraffes survived, we would also expect to see a current day population of long-necked giraffes even though short-necked giraffes would have done just as well.