apt only autoremoves packages it installed as dependencies. Everything you installed by name stays forever, even helper libraries you only needed once. apt-mark auto moves them to the other pile.
Mark the package, then see what autoremove would do:
sudo apt-mark auto build-essential libssl-dev
apt-mark showauto | grep libssl-dev
sudo apt -s autoremove
From now on apt treats these as dependencies. If another installed package still needs them, they stay. If nothing does, the next apt autoremove takes them away.
I find this handy after compiling something from source. You install a list of -dev packages to build it, and once it’s built they just sit there. Marking them auto means a later autoremove cleans them up without you keeping a list.
The reverse is apt-mark manual. That one is worth knowing too: if autoremove wants to remove something you use directly, like curl pulled in by another package, mark it manual and it stays.
Always run the simulated autoremove first. Marking something auto that nothing depends on means it goes on the next autoremove, and some packages are things you use every day without ever having asked for them by name. Read the list before you confirm.
Further reading: apt-mark(8) manual page