Abstract A method was developed for the quantitative analysis for calcium and magnesium in sodium–matrix waters using capillary electrophoresis with indirect detection. Separation of the divalent metals from the matrix ion was investigated via addition of a weak diacid in the electrolyte. The optimum separation conditions were chosen after simulations of the migration times of the cations at pH 5.0 and were experimentally tested. Among the selected diacids, oxalic acid and tartaric acid gave the best peak-to-peak resolution for all the cations. The cationic chromophore was selected from a series of weak bases. Optimisation of the sensitivity for the alkaline–earth metals was investigated via alteration of the electrolyte pH to adjust the mobility of the chromophore to those of the cations. The best analytical conditions were obtained with 10mM creatinine/2mM oxalic acid, pH=4.6 and 14.4mM benzylamine/8mM tartaric acid, pH=4.8. System peaks were sometimes present in the potassium and sodium regions but did not interfere with the quantitative treatment. Limits of detection of 4μM were achieved in a simulated matrix containing 500 ppm of sodium, whcih corresponds to the upper limit for the matrix–ion concentration. The proposed method was applied to the determination of calcium and magnesium ions in saline underground waters.