Yes, you can keep your number when switching to 5G and the process is simple.
If you’re upgrading on your current network then your number will stay the same anyway, but if moving network you just need to request your PAC code from your old network (while the number is still active), then activate your new SIM if you haven’t already, and tell your new network your PAC code and old number.
Requesting your PAC code can be done by texting ‘PAC’ to 65075 from the number that you want to keep. Giving the code to your new network is usually done via on online form, but the exact process will vary from network to network. If in doubt, give your new network a call.