Keys and keyways are one of the most common shaft–hub connections. Despite this fact very little numerical analysis has been reported. The design is often regulated by standards that are almost half a century old, and most results reported in the literature are based on experimental photoelastic analysis. The present paper shows how numerical finite element (FE) analysis can improve the prediction of stress concentration in the keyway. Using shape optimization and the simple super elliptical shape, it is shown that the fatigue life of a keyway can be greatly improved with up to a 50 per cent reduction in the maximum stress level. The design changes are simple and therefore practical to realize with only two active design parameters.