The k-means algorithm is based upon an iterative process.
First, we decide how many clusters we desire. The number of clusters can be determined by a number of methods, but bear in mind that there is really no correct number of clusters. Typically, between 3 and 20 clusters can be used as a range.
As an initial step, cluster members are randomly assigned to one of the three clusters that have been specified. In the following example, we have 12 observations (in gray), and three centroids (solid colors) which have been randomly generated. For this example lets make believe we have only two variables, lets say there were age, and height. We will represent them on an x and y axis but we wont label them:
The next step is ...