In this article we derive optimal upper bounds on the dimension of the attractor for the Navier-Stokes equations in two-dimensional domains, these bounds fully agree with the lower bounds obtained by Babin and Vishik (1983) (see also Ghidaglia and Temam, and Liu (1993)). As in Babin and Vishik (1983), we consider here elongated domains and leaving the density of volume forces and the viscosity fixed, we let the shape ratio of the domain become large so that the Grashof number is large. The estimates derived here are based on the general methods for estimating attractors dimensions as in Constantin et al. (1988), on a new version of the Lieb-Thirring inequalities for elongated domains and on techniques developed for such domains in RS (1993), and Temam and Ziane (1996). At the end of the article, we also give some partial results in the three-dimensional case for which we need a physical assumption on the Reynolds number introduced in Ghidaglia and Temam.