The algorithm starts by randomly initializing 'K' centroids. Each data point is then assigned to the nearest centroid, forming clusters. The centroids are recalculated as the mean of the data points in each cluster. This process is repeated until the centroids no longer change significantly or a maximum number of iterations is reached.