How the algorithm actually runs
K-means is the most common clustering algorithm because it's simple and fast. You start by picking a number k, the number of clusters you want. The algorithm places k cluster centers, called centroids, then repeats a two-step loop: first, assign every data point to whichever centroid is nearest to it, second, recalculate each centroid as the average position of all the points currently assigned to it. Those two steps repeat, assign then recalculate, until the assignments stop changing between iterations, meaning the centroids have settled into stable positions.
The result is k groups of points, each clustered around its own centroid, with every point belonging to exactly one cluster. It's a genuinely useful algorithm precisely because it's mechanical: no labels, no training against a target, just repeated distance calculations and averaging until the system stabilizes.
