Rest periods get treated as an afterthought by many beginners, when in reality the right length depends directly on what a specific exercise is training toward.
Strength work needs longer rest
Heavy, low-rep strength work depends on near-full recovery between sets, which generally means longer rest periods than a lighter, higher-rep set would need.
Hypertrophy and endurance tolerate shorter rest
Muscle-building and endurance-focused training can use shorter rest periods, since the goal there is more about accumulated fatigue and volume than maximal single-set output.