As with email, there's also always the option to use a custom domain you control for your instance. There are a couple of SaaS providers for Mastodon instances like https://masto.host, and cookbooks for several DIY options on major hosting providers. A benefit to custom domain is that you have some power to migrate your CNAME records if you had to switch hosts, and keep your existing followers even.
As others have said you can backup your data, which is a good rule of thumb everywhere.
There's also a migration feature that lets you say "I'm at this new handle now" on an old profile. But I don't think it automatically brings your old followers with you.
Note that these are only viable if you know ahead of time that the instance is going away (this is happening right now with witches.town which is closing at the end of April).
Migrating posts is complicated -- it's straightforward to export all your posts with third party tools, but you shouldn't expect to be able to move them to a new instance unless you're running it yourself, in order to avoid the possibility of faked histories. (I personally keep a backup of all my posts, and it's fairly straightforward to re-format them as a static html document if you feel like you need to re-host them for archival purposes.)
Personally, I recommend keeping accounts on several instances, and posting to different accounts corresponding to your various interests. This makes it less irritating for members of your social group that don't want to hear about particular topics, makes migration in case of instance apocalypse easier, and encourages you to stretch out your identity a bit (rather than feeling like you need to stay 'on-brand' like people do on twitter).