Historically patients were told to always finish every tablet to avoid leaving behind hardier bacteria that could survive and regrow. The most important rule is to follow the exact instructions your doctor or pharmacist gave you for your specific infection.
Medical thinking has been evolving: for some infections, shorter courses are now recommended, and stopping at the planned time matters more than an arbitrary fixed number of days. What you should not do is stop early on your own just because you feel better, or save leftover tablets for next time.
If you are unsure how long to take them, or you are getting side effects that make you want to stop, contact your prescriber or pharmacist before stopping rather than guessing.