Our brain has a wonderful facility to take in what we perceive, and turn it into something we can parse and understand. Did you ever see one of those little drawing games, in which only part of an object was depicted, and you had to figure out the rest? Or watch "Name That Tune," which is based on the same phenomenon?
Art history students are aware that for much of early history, drawings of people weren't very realistic. It wasn't that the artist wasn't trying to draw true to life, but that he or she didn't understand the anatomy of a complete human being. They knew that an arm went here, and an ear went there, but they didn't look carefully at how an arm is shaped, and how exactly it supports the whole form. It wasn't until artists like Michelangelo peeled the body down to its core elements, and then learned to only suggest the essence with a gesture, a line, a squiggle, that drawn humans began to look, well, human.
Most of the conversation we hear is about thoughts, and is not very focused on the words used to convey the ideas. Our brain leaps ahead when we listen. Therefore, we don't actually hear all the words. In return, we don't speak all the words, either, because we become subconsciously reliant upon the brain's ability to make connections based on partial information. Writing dialogue becomes difficult when we don't understand the entire anatomy, and the persistent shortcuts used to reference that whole. We try to write the entire thought out, but the resulting language is stilted because in real conversation people jump over most of the words without losing the context. It doesn't matter whether the participant is speaking or listening, the missing elements are understood.
Good written dialogue is spare. Don't say too much! Grammar within quotation marks should only be as correct as would be true to the character (don't forget, spoken language is often grammatically incorrect). Grammatical errors should only be fixed to the extent necessary for the reader to understand what the declarant is saying, and remember, most people can name that tune with very few notes.
The best way to learn how to do this, is to listen to as many conversations as possible. Pay attention to the 'how' it is being said, not the 'what' of the subject matter. Then, permit the people in your writing to speak just like we do, with drips and drops of more or less poorly worded semantics that nonetheless, get the point across. Let your description of the surrounding non-verbal elements provide an environment rich in meaning to help provide the essential clues that the dialogue leaves out.