It depends a lot on where you are; There are a few principles that apply to most of the EU, defined in the so-called "return directive" but most of the rules are defined at the national level and implementation might even differ between areas in the same country.
Worse case scenario is that you would immediately receive a return decision enjoining you to leave the country. This would, in all likelihood, give you a delay for voluntary departure. After that delay, you could be detained and/or removed and in some places the police might actively look for you (e.g. by checking your last known address). When you go through the removal process, you might receive a fine or even a ban from the whole Schengen area (for Schengen countries) for a number of years.
Best case scenario is being able to stay illegally for some time before finding another solution. You could still potentially face the process described above at any time (if you are caught after a period of illegal stay, you would probably not be given any delay for voluntary departure and face immediate detention until the authorities find a plane to send you to whichever country would accept you). There are two ways out of this situation:
- Leaving voluntarily. Legally, it's still possible to receive a fine or even a ban upon leaving but not all countries use this aggressively, so the best case scenario is that you leave and nothing much happens.
- Finding a legal status. If you live many years in a country, maybe build a family, etc. you might be eligible for some sort of amnesty or a residence permit on humanitarian grounds. Here again, it all depends on your exact situation and the country where you are but that would another best case scenario (it's not easy and it would be foolish to rely on it but it does happen regularly).
Note that once you stayed illegally in a country, you can still face negative consequences many years after the fact, even if you escape the worse immediate consequences and manage to leave and/or find some legal status to stay. For example, an earlier period of illegal stay can be valid grounds to refuse a naturalisation decades later. Getting another visa could also become (much) more difficult.