Natural selection can be expressed as the following general algorithm:
Note that the above algorithm is made with no explicit reference to biological entities. Thus, a form of natural selection could occur in the non-biological realm. Note also that this formulation does not rule out selection occurring at all biological levels (e.g. gene, organism, group). Nor does it matter what the cause of variation is: some creationists, for example, generally accept that evolution occurs, but posit that God causes the changes that lead to it.
Darwin first outlined his theory in two unpublished manuscripts written in 1842 and 1844 and more fully developed it for publication in The Origin of Species, especially Chapter 4.
See also; [artifical selection]?, sexual selection, evolution