There is no exact definition for either. The line between them is sometimes clear; sometimes not.
In general, if two populations have a high degree of mutual intelligibility (but they don't speak identically), then they speak dialects of the same language.
If the two groups have a great deal of difficulty understanding each other, then they speak different languages.
However, there is no set parameter on how much the groups need to understand each other to qualify as a dialect versus a language.
Further, one group may understand the other group better than vice versa, further complicating matters.
In addition, many languages extend over a geographical continuum, where neighboring villages and cities understand each other fairly easily, all the way across the continuum, but villages widely separated from each other many not understand each other very well at all.
Languages evolve into new languages by first diversifying into dialects. Those dialects continue to change. When they are no longer mutually comprehensible, they are different languages. Sometimes some of those dialects go extinct, leaving only one survivor.
Dialects are more than different pronunciations. Sometimes there are different spellings, vocabulary, and grammar as well.
In addition, there can be different dialects within the same area, due to differences in ethnicities, social class, education, etc.
In the USA, for example, most people refer to Pepsi, Coke, etc as brands of soda. However, in Michigan, although we understand "soda", we use the word "pop". In some other American dialects, "coke" refers to any soda/pop and just the Coca-Cola brand.
Governments can also dictate the use of the label as well. The majority of linguists outside of China find that China has several mutually incomprehensible languages (and there are dialects within each one). Note though that most people learn to read/write Mandarin, so that is often considered a common written language. However, there are written forms for the other Chinese languages as well, with different syntax, idioms, and sometimes even different characters.
China, however, insists for political/cultural reasons that there is one Chinese language (Mandarin) with many dialect groups (each one having subdialects as well), even though those main dialect groups don't understand each other in spoken form. The rest of the world considers them to be separate languages, for the reasons described above.
There is no "exact" difference between language and dialect. Living languages/dialects also continue to change over time.
Lastly, there is currently a bitter debate whether or not Scots is a dialect of English or a closely related Germanic language (not to be confused with Scottish English - a definite dialect - or Scottish Gaelic - definitely another language, a Celtic one).
Scots can often be impossible for an American like me to understand, even in just written in form. It's definitely closer to being a separate language than say Irish English or Southern English in the USA. A few hundred years from now, if they both still exist, I am certain that Scots and English will have changed enough that they will have become different languages.