How does YouTube encode my uploads and what codec should I use to upload?
Some general info about the formats used:
YouTube uses 4 container formats and 4 different codecs. It depends on the popularity of the video what codecs are used for your video (see below why). Generally, every of your uploaded videos will be encoded in h.264 and will be muxed into an .flv and .mp4 container. That's the standard and this will happen for every video. Though .flv will only be used for resolutions below 720p. Meaning only 360p and 480p will exist in an .flv container. Though every video below 720p will also have a mp4 version available. For 240p YouTube is also using 3gp which is a rather old codec (based on MPEG-4 Part 2 (not to be confused with MPEG4 Part 10 aka h.264) meant for mobile devices (long before the smartphone era), it comes in the container .3gpp.
The other codec used is VP8 which is coming in the WebM container format. WebM is a format developed by Google and was meant as a standard video codec for HTML5, support for it is by now pretty good in most modern browsers.
WebM was introduced with the HTML5 version of YouTube. YouTube only encodes some videos in WebM after they got uploaded and mostly only popular videos (going by the videos I saw encoded in WebM) so it's not certain your video will be present in WebM. Though this is changing with WebM gaining some more support.
YouTube also supports VP8/VP9 in the WebM container. This is supported by all major browsers for several years now. With WebM, they also introduced support for the Opus audio codec (besides AAC which is used in all other containers).
In regard of your linked question (maybe they should be merged?)
What codec/container should you use for uploading?
That depends, if you are limited/concerned by your upload speed then use h.264 Level 3.1/4.1 with Main Profile for SD or High Profile for HD. YouTube will accept this just fine and it will look nice after it got encoded by the YouTube servers. I would usually recommend a bitrate of ~4-5 Mbit/s for 720p material and ~8-9 Mbit/s for 1080p. For 4k go for ~15-25Mbit/s or more depending on the complexity of the footage. &quot;Cartoon&quot; content with few colours can usually have a much lower bitrate in general.
This is usually a good balance between size and quality. If you want better quality go with a higher bitrate, and if you want a smaller video go with a lower bitrate.
But be aware that YouTube will ALWAYS encode your video once it's uploaded, doesn't matter what codec and settings you use. So if you want the theoretically best quality for your uploads, choose a lossless codec for uploading or at least visually lossless.
See YouTube as the final output into a delivery/consumer format and the upload to YouTube is the last step in production and during production you want to stay lossless.
But please note this is all just a theoretical thing, practically I'd say it really doesn't matter as we are talking about YouTube and not about TV broadcast or Cinema. In almost all cases a very high bitrate h264 encode (20-40mbit/s) will suffice even for high-end content.
But if you really want to do it the &quot;perfect&quot; way, use a production codec and not a consumer codec like h.264.
MJPEG would be a good codec for that, YouTube definitely supports that in an .avi or .mov container. MJPEG is a lossy codec but the visual quality will be the same as the source (if you chose a high enough quality setting, this is practically JPEG as the video codec).
Going with a real lossless codec would be a waste of hard-drive space and bandwidth in my opinion.
But if you want to upload your video truly lossless and don't care about the upload time, I recommend using a standard QuickTime codec as they should be nearly all supported by YouTube (note that not all of them are lossless, h264 is also a standard QuickTime codec). Though YouTube doesn't state which QuickTime codecs are supported, unfortunately. Animation or JPEG2000 should work I guess. Both codecs can be 100% lossless depending on settings in case of JPEG2000.
When it comes to frame rates, if you can choose then use 25FPS or 30FPS  during recording/animating (by now YouTube also supports 50 and 60FPS+ video, so use that if your content benefits from a higher framerate), YouTube likes standard framerates like 25 or 30FPS the most (or again one of the higher FPS options) but if your footage comes already in another frame rate like 24FPS then stick with that and don't interpolate up or down. YouTube will handle the conversion for you and generally does that better then your average encoder. They have to deal with all kind of framerates every day and solved this (actually very complicated) issue really well.
Audio:
For the audio use PCM if you want to stay lossless with the audio as well but again this is really just a theoretical quality improvement. AAC will usually do the same job quality wise (subjective) and will be smaller. I recommend a bitrate of at 128-192kbps for AAC. The size impact is usually not as big as the video codec so you can also just go with 192kbps or higher if you feel your audio content is very sensitive. YouTube will convert audio to ~24kbps(Mobile aka 3gp) ~64kbps(240p), ~128kbps(360p/480p) and ~192kbps(720p+) using the AAC and Opus (WebM only) codec.