Through plenty of experimenting over the years with a number of different tools and encoders.
I usually find the right settings for a particular phone I have based on specs and display or sometimes encode one in high quality that will play in any phone just fine and look great. As an example, I can sometimes turn an edited full 1080p capture that is 1.8GB into a 400MB file that plays flawlessly and looks amazing both on a phone and even on your computer as well. It just depends on what you are after and how much time you are willing to spend on it. However, once you know the settings, it is extremely easy to encode them and the only time spent is the encoding time itself.
I can't possibly go over everything here but there are a handful of software apps out there (most free) that are excellent and work well for this. I have actually been using some of them for many years now.
--mike