Criteria for designing good space-time trellis codes (STTCs) have been developed in previous publications. However, the computation of the best STTCs is time consuming, because a long exhaustive or systematic computing search is required, particularly for a high number of states and/or transmit antennas. To reduce the search time, an efficient method must be employed to generate the STTCs with the best performance. In this paper, a technique called coset partitioning is proposed to easily and efficiently design optimal 2 <sup xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">n</sup> -phase-shift keying (PSK) STTCs with any number of transmit antennas. Coset partitioning is an improved extension to multiple-input-multiple-output (MIMO) systems of the set partitioning proposed by Ungerboeck. This extension is based on the lattice and coset Calderbank approach. With this method, optimal blocks of the generator matrix are obtained for 4-PSK and 8-PSK codes. These optimal blocks lead to the generation of the STTCs with the best Euclidean distances between the codewords. Thus, new codes are proposed with three to six transmit antennas for 4-PSK modulation and with three and four transmit antennas for 8-PSK modulation. These new codes outperform the corresponding best known codes. In addition, the first 4-PSK STTCs with seven and eight transmit antennas and the first 8-PSK STTCs with five and six transmit antennas are given, and their performance is evaluated by simulation.