There are two different theories I`ve created with anime evidence to create an answer.
Theory Number One:
In the first season of the anime, there is a very early on episode where it shows where ash's pokeballs are stored, and that happens to be on his belt, which is concealed by his jacket most of the time. My theory is, he has them in a pattern similar to the games (first, second, third, etc.), so that he can easily remember which Pokemon is where, and since he's been on his journey for a while, and has had the experience, it`s become natural to him to know which Pokemon is at on his belt.
Theory Number Two:
There was an episode in the anime (battle frontier season, I believe, not sure) where butch and Cassidy were holding a battle area sort of thing where they were stealing a bunch of pokeballs. Long story short, Jessie, James, and Meowth got involved and the plan screwed up, and a lot of pokeballs got spilled around the arena. Trainers were picking the pokeballs up, and suddenly knew if their Pokemon was in the pokeball. So, I have developed a theory, Each trainer's name and the Pokémon and it's stats are engraved on the bottom of the back of the pokeball. Therefore, the trainer checks the back of the pokeball, and looks for their name and their Pokemon and it's nickname (if it has one).
Alltogether, I doubt we`ll ever TRUELY know how to determine how a Pokemon trainer figures out how what Pokemon is in each pokeball. But, I feel my two theories at least shed a little light on this petty, but intriguing, mystery.