If a compound has two carbonyl groups (dicarbonyl compound), it undergoes an intramolecular aldol reaction if a five- or six-membered ring can be formed:

What happens is one of the carbonyls is deprotonated at the ɑ position, thus serving as a nucleophile, and attacks the C=O carbon of the other carbonyl. It is always a good idea to number the carbon atoms to keep track of their movement:

Formation of a six-membered ring follows the steps and mechanism: deprotonation, intramolecular aldol addition, proton transfer, and E1CB elimination to yield the ɑ,β-unsaturated carbonyl compound:

Notice that the deprotonation of carbon 7 leads to the same product, and in general, it represents the same reaction because of the molecular symmetry.
On the other hand, if either carbon 3 or 5 is deprotonated, the intramolecular nucleophilic attack leads to a four-membered ring. However, remember that five- and six-membered rings are the most stable, and the four-membered aldol product is an unfavorable product of this equilibrium:

Other common intramolecular aldol-type cyclization reactions are the Robinson annulation and the Dieckmann condensation, so check them out for additional strategies for forming cyclic carbon-carbon bond frameworks.
More examples to practice Aldol Condensations are given here:
Aldol Addition and Condensation Reactions – Practice Problems
Crossed Aldol And Directed Aldol Reactions




