Elbow method, silhouette score, gap statistic, or domain knowledge.
How to answer it
There is no ground truth, so the honest answer combines a statistic with the question the clusters are for.
Elbow: plot within-cluster sum of squares against k and look for the bend where adding clusters stops paying. Cheap, often ambiguous.
Silhouette: for each point, how close it is to its own cluster versus the nearest other; average over points, pick the k that maximises it. Better defined than the elbow, expensive on large n.
Gap statistic: compare the within-cluster dispersion with what random data of the same shape would give; pick the smallest k whose gap is within one standard error of the best.
Stability: cluster bootstrap samples and check whether the same k gives the same clusters. Unstable clusters are noise.
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score
scores = {k: silhouette_score(X, KMeans(k, n_init=10, random_state=0).fit_predict(X)) for k in range(2, 11)}
Then the constraint that usually decides it: what will be done with the clusters. A marketing team can act on four segments and not on eleven. If the silhouette says six and the business can use four, four with a note is the right answer.
Standardise features first, since k-means uses Euclidean distance and an unscaled column dominates; and remember k-means finds round, similar-sized blobs, so if the data is not shaped like that no k is right and the method is wrong.
What they are checking: that you name a statistic and then override it with the use case.
Common mistake: reading a k off the elbow plot as if it were a measurement.