Overstaying is one of those mistakes that can follow you around for years, so take it seriously even if it was accidental. Consequences vary a lot by country: some charge a per-day fine payable at the airport on exit, others impose entry bans ranging from months to several years, and long or repeat overstays can lead to detention or deportation in stricter jurisdictions.
Even a short overstay usually gets recorded in the immigration system, and you may be asked about it on every future visa application anywhere. Declaring a past overstay honestly, with an explanation, is almost always better than having it discovered later.
If you realize you are about to overstay, contact the local immigration office before your permitted stay ends. Many countries allow extensions or grace periods for genuine emergencies like illness or cancelled flights, but usually only if you approach them proactively. Check the immigration department's official site or your embassy for the exact rules.