This paper studies the problem of selecting relevant features in clustering problems, out of a data set in which many features are useless, or masking. The data set comprises a set U of units, a set V of features, a set R of (tentative) cluster centres and distances d ijk for every i ∈ U , k ∈ R, j ∈ V . The feature selection problem consists of finding a subset of features Q ⊆ V such that the total sum of the distances from the units to the closest centre is minimized. This is a combinatorial optimization problem that we show to be NP-complete, and we propose two mixed integer linear programming formulations to calculate the solution. Some computational experiments show that if clusters are well separated and the relevant features are easy to detect, then both formulations can solve problems with many integer variables. Conversely, if clusters overlap and relevant features are ambiguous, then even small problems are unsolved. To overcome this difficulty, we propose two heuristic methods to find that, most of the time, one of them, called q-vars, calculates the optimal solution quickly. Then, the q-vars heuristic is combined with the k-means algorithm to cluster some simulated data. We conclude that this approach outperforms other methods for clustering with variable selection that were proposed in the literature.