Butter is the result of separating the milk or butter fat from the water and milk solids in milk. Generally, it is made from cream that has separated from the milk because that is a much more efficient and less wasteful way of getting butter out. The fat globules in milk are surrounded by a structure that resists having them stick together and form lipid crystal structures, so the fat needs to be agitated until the protected layers break down and the fat can begin to stick. We call this churning the cream, and when it finally occurs most of the water and the milk solids separate out into buttermilk, while the butterfat (along with some residual water and milk proteins) stick together and stay behind.
Typically, butter that is churned and processed at home has a higher butter fat proportion (over 85%) as compared to commercially-processed butter. In the USA, butter is required to have 80% or more butter fat by law, but in other countries that requirement can be higher. Butter is typically composed of about 2% milk solids, 80-86% butter fat, and the rest (12-18%) is water.
Churning your butter out can be done in many ways. A shaker bottle, a dedicated butter churn, a kitchen stand mixer with a whipping attachment, a blender, and so on can all do the work. Some will do it with more or less mess, some with more or less manual effort, but it usually takes approximately 20-30 minutes. The ideal temperature of the cream is 50-60 degrees F; any colder and it will take more effort to agitate, and any warmer and it will resist sticking and separating.
At first, it will look like nothing is happening. After a little while, the cream will start to set up and stiffen as in whipped cream, and if you stop there, that is what you have. Continue whipping and agitating and suddenly the fat will begin to fall out and stick to the other fat in small little balls and chunks, and eventually you'll see a fairly coherent mass of butter in the middle of a pool of buttermilk.
The buttermilk can be saved, and the remaining butter needs to be further processed so it will keep well.
Butter needs to be washed, because it will still contain an amount of residual lactose and excess whey-like water than will cause the butter to go rancid much faster if it's left in. It feels counterintuitive to remove water and such with water, but the process does work. After pouring off the buttermilk, pour in some cold, clean water and use a good spatula, spoon, butter paddles, etc to work, turn, and mush the butter around. The water will become cloudy with the residuals that you do not want to stay in. Pour that off, and repeat the process again a few times until the water is staying almost entirely clear and clean when you pour it off. Try to get as much of the water out as you can by working it some more.
If you want salted butter, which will help it keep longer and help remove some more water, you can add 1-2% of the weight of the butter as salt, work it in, and pour off any additional water that comes out as you work it.
Finally, press the butter into the shape you like, and put it in a container, wax paper, or some other form to protect it from whatever might float around in the air in your fridge, and leave it there to keep. There are dedicated butter presses available from homesteading supply stores to press the butter into a nice boxy shapes, but a ball of butter can be easy to make as well and easy to work with.
Butter that has been processed well can keep on the counter top for a week or two, but as always, it will keep longer in the fridge. Also, to avoid rancidity, keeping it out of light (especially direct sunlight) is important. Butter that has been hand-churned and pressed typically is softer at fridge temperatures than commercial butter, so keeping it in the fridge is less of a problem for spreadability.
Historically, butter was cultured and was a more flavorful, tangy dairy product. The cream itself was directly cultured or left to sit out for a day or two as the natural raw milk cultures would go to work on it and start acidifying it. Once the cream was showing a little bit of thickening and some tang, it would be processed as above into butter and buttermilk. The buttermilk would further thicken after that into our cultured buttermilk, while the butter would be protected by having most of the lactose already converted to lactic acid. Cultured butter is easier to separate and keeps longer due to the action of the cultures, because residual lactose promotes the butter going rancid.
In Europe and many other places in the world, cultured butter is still very common. In the USA it has fallen out of favor, and most people don't even know it exists.
A typical culture for culturing cream intended for butter is a mesophilic aeromatic culture mix, such as a buttermilk culture or a Flora Danica culture. A mesophilic clabber culture also works well. Finally, any butterfat that is left in the vat from cheese making is already cultured and that with some whey left over in a cool place to get the butter fat on top is a great way to get a little extra out of your cheese making session. It will still need to be agitated to some to collect the butter, and washed and so on as above, but it should take less time as the butterfat already largely separated out during cheese making.
The process of churning butter will gel all of the fat (along with some residual water and some milk solids), but a large amount of liquid and some solids will be left over. This is buttermilk, and when the cream was cultured beforehand this will be cultured buttermilk. Cultured buttermilk in particular is prized for cooking and baking due to its acidity, and when left to culture long enough it will begin to thicken somewhat and add body to the buttermilk. Buttermilk is similar to whey in its composition.
Commercial buttermilk is often just skim milk, cultured and with thickeners added. Its consistency is similar enough to true buttermilk that consumers can usually use it without a second thought. But true buttermilk is the separated product from butter.
After cheese making, depending on the type of cheese and curd handling, the leftover whey may have some butter fat left in it. If it is similarly shaken/churned after it cools, some cultured butter can be obtained and the resulting separated whey can likely be used as buttermilk as well.