Ancient Greek had a lot of different dialects. It's kind of hard to give an exact number because there are different categorizations and sub-categorizations, and you can find peculiarities in the inscriptions from dozens of different cities and islands, but they get grouped into a few main dialects: Attic, Ionic, Aeolic, Doric, and Arcado-Cypriot. For Ancient Greeks, ethnic identity and language were closely linked; Greek ethnicity was defined by speaking Greek, and many ancient writers considered Attic, Ionic, Aeolic, and Doric to be the main categories of Greek people as well as the four dialects.
The short answer to your question is that, while there's a bit of uncertainty on the details, yes, speakers of different Classical Greek dialects could mostly communicate. There were significant differences between dialects, but people could definitely understand each other for the purposes of basic communication.
How do we know this? One form of evidence is the distribution of dialects in literature: different works of literature were written in different dialects, and the dialect (or mixture of dialects) a work was written in didn't necessarily correspond to the dialect that was spoken in a writer's home. That's largely because different genres came to be associated with different dialects. For example, elegiac poetry was originally written in Ionia, writers who weren't from Ionia wrote their elegies in the Ionic dialect. In the extreme case, Athenian tragedies actually included two dialects: the dialogue was written in Attic (which is what people in Athens actually spoke), while the chorus' songs were written with features of the Doric dialect. So unless your average audience member at an Athenian festival was studying the other dialects before heading to the theater, it seems like Attic speakers could basically understand Doric. You might compare it to British singers who sound somewhat American when they sing. Also, Athenian comedy plays have characters whose speech parodies various non-Attic dialect features (not going for accuracy, just for flavor and humor), so it's clear that audiences were familiar with other dialects and found them weird enough to mock but not weird enough to disrupt their understanding of the plot. There's even a joke where an Attic-speaking character misunderstands a Megarian character, which presumably wouldn't be funny if the audience didn't find the Megarian's speech both unusual and intelligible. Some writers of prose history mixed dialects for the simple reason of (allegedly) quoting a source verbatim; Thucydides has no problem with leaving quotes in Doric dialects.
To be fair, it wasn't like people were reading with no prior knowledge of other dialects; they'd had lots of practice by in reading other dialects, as well as literature written in a mix of dialects, like Homer. Other evidence, though, is a bit more explicit. In Athenian legal speeches, native speakers of other dialects were typically reading out speeches in Attic prepared for them by an Athenian lawyer, and they sometimes apologized for their accents (just the same as rustic or low-class Athenians did)!
A less clear-cut piece of evidence, but still relevant, is just the fact that there are lots of anecdotes in ancient sources where people interact with speakers of other dialects, and they don't mention translators or anything. People had alliances and negotiations and embassies. Xenophon talks about the "Ten Thousand" mercenaries from all over Greece acting as one military force.
But communication across dialects wasn't perfect. Sound correspondences and differences in verb conjugation are the most noticeable. If we trust explicit ancient evidence, vocabulary differences seem to have been the biggest difficulty. We have instances where an author will explain what one dialectal word means in another dialect, like when Thucydides (writing in Attic) says that ἄτρακτος in Doric means ὀϊστός 'arrow'.