Why does macOS have many strange ports open and what do they do? 50323, 50334, 50641,57621, 57650, 64448
I have compiled a list of all the services and what they do.

Checking it yourself

If you have different ports open and want to check for yourself, you can use

sudo lsof -i :50323 to see the service running on the port 50323.

ps aux | grep rapportd to find out some more information about the service rapportd, like the executable path.

codesign -vvvv -R="anchor apple" /usr/libexec/rapportd to see if the service is correctly signed by Apple. Doesn't apply to programs that aren't made by Apple.

man rapportd to read the documentation about the service

Results

Port 50323:

Service rapportd at /usr/exec/rapportd, signed by Apple. It is a Daemon that enables Phone Call Handoff and other communication features between Apple devices.

Port 50334:

This is Spotify, which is a music streaming service. Not installed by default. I think it might be related to Spotify Connect, a service which allows connecting your phone to your computer, and streaming music from your computer to your phone (or any other device which supports it)

Port 50641:

This is IntelliJ Idea, an integrated development environment for programmers. Not installed by default. Also it's tcpwrapped, meaning you can't actually do anything with it, since it drops the connection whenever you actually try to send it anything (correct me if I'm wrong). I think IDEs usually need a port open for the debugging functionality.

Port 57621:

Also Spotify.

Port 57650:

This is gradle's daemon. It's a tool programmers use. Not installed by default. Also it's tcpwrapped. Not sure why it needs to be listening on a port. If someone knows, then I'd be curious to know.

Port 64448:

Also gradle. tcpwrapped.