In this paper, we construct explicit exponential bases of unions of segments of total measure one. Our construction applies to finite or infinite unions of segments, with some conditions on the gaps between them. We also construct exponential bases on finite or infinite unions of cubes in $\mathbb {R}^d$ and prove a stability result for unions of segments that generalize Kadec’s $\frac 14$-theorem.