When you buy bitcoin do you get the private key mailed to you? I'm very confused about how you get your private key and how you can transfer it.
When you buy bitcoin do you get the private key mailed to you?


No

There are lots of ways to buy bitcoin but usually I'd expect they don't involve creating a private key at all. You should ideally already have one before buying Bitcoin.

If you buy Bitcoin on a service that keeps your Bitcoins in some kind of customer account then most likely you don't have any private keys and are not the owner of Bitcoin - just the possessor of a kind of IOU.


  I'm very confused about how you get your private key ..


It varies but perhaps the most common way is that you download and install a standalone wallet program and, the first time you run it, it generates a random private key and stores it in a wallet data file. Typically you never see it.


  ... and how u can transfer it


You rarely need to.

Many wallets have a function to create a backup. You then put that backup somewhere safe that is separate from your computer. That backup will contain the private key. If your wallet (or whole computer) is destroyed or lost, you can re-create your wallet from the backup.

Many wallets will give you a "recovery phrase", sometimes called a "seed phrase". Often of twelve or twenty-four words. You can save that recovery phrase somewhere safe (e.g. stamped onto a sheet of corrosion-resistant metal with a high melting point stored in a safe in another building). That recovery phrase can be used to re-create your private key in a new wallet on a new computer. Don't confuse the recovery phrase with a password or pass-phrase used to open a wallet.

Many wallets let you see the private-key in some form. There is a form called WIF. Again that can be stored somewhere safe and used to recreate a new wallet with the same private key.

If you don't like your current wallet and want to start using a new type of wallet, the safest process is to create a new wallet and, on the old wallet, create a Bitcoin transaction to transfer the money into the new wallet. Some wallets allow you to "sweep" keys into them which is the same process but uses only the new wallet to create the transaction.