When your car is totaled, the insurance company has an obligation to "make you whole," as is defined in your policy. This essentially means you need to be placed back in approximately the same financial position (with respect to the item insured -- not in respect to any liens or leases that hold title to your car) you were in before the accident occurred.
Most policies value your vehicle using actual cash value. Actual cash value (ACV) basically means replacement value less depreciation. The insurance company looks at the value of the vehicle, in the condition it was in the moment before the accident occurred, to determine its ACV. (Find out more here on how the actual cash value is determined by insurers).
If you have physical damage coverages (comprehensive and collision), then if your insurance company is the one covering your totaled vehicle they will typically write you a check for the actual cash value of the vehicle, minus the deductible that is due.
If your car were totaled out by another driver that was at-fault, then that person's property damage liability coverage should pay out ACV for your vehicle, but no deductible will be due.
If the car is financed or leased, then the title holder that you have listed as a loss payee on your car insurance policy will also need to be involved in the settlement process. Don't try to keep the settlement check for yourself -- that could lead to problems.
If you are "upside down" (owe more on a car than it's worth), then you should consider gap insurance. This is because if the cash value of the vehicle is less than your current loan amount and your car is totaled out you will be responsible for the remaining balance of your loan after ACV is paid out by the auto insurer. The terms of this payment are set through your loan contract.
During the settlement process, you will sign over your totaled out vehicle to the insurance company that is paying you ACV for it. The vehicle then becomes their property, which they will usually sell at auction to recoup some of the money paid out on the claim. If you'd like to keep the totaled vehicle and fix it on your own, then you can see if you buy it back from the insurance company.
If your car has been totaled, gauge your coverage options using our car insurance calculator. Make certain before insuring a new car with your current auto insurance provider that you are getting the cheapest premiums possible.