Tidally driven residual circulation in shallow estuaries with lateral depth variation has been studied analytically using a two-dimensional, depth-averaged model. The solution is presented for a v-shaped channel. Exchange flow is found to be correlated with the topography. The magnitude of this exchange flow depends mainly on four parameters: the ratio between the minimum depth on the shoal and the maximum depth in the channel, the ratio between the tidal amplitude at the mouth and the mean depth, the ratio between the length of the estuary and the tidal wave length, and the ratio between the tidal timescale and the decay timescale due to friction. Generally, a net landward flow occurs over the shoals and is balanced by a return flow in the channel. The along-channel residual velocity changes nearly linearly across the estuary. The residual velocity decreases monotonically toward the head of the estuary. The transverse residual velocity is convergent in the channel and divergent on the shoals. The residual velocity is highly dependent on the length of the estuary. When the length of the estuary is much smaller than a quarter of the wave length, the residual velocity is relatively small. When the length of the estuary is about a quarter of the wave length, the magnitude of the residual velocity reaches its maximum. When the length of the estuary is much larger than a quarter of the wave length, the residual circulation approaches the pattern found in an infinite length estuary. On the basis of the analysis of the solution, we conclude that exchange flow generated by tides in a shallow estuary is the result of competition among several processes. An inward flux is caused by local nonlinearity, both in the bottom friction and from propagation of the tidal wave of finite amplitude. This inward flux is larger on the shoals and smaller in the channel owing to larger nonlinearity in the shallow water. The residual inward flow creates a setup (residual surface elevation) of water at the head of the estuary that produces a pressure gradient. This residual pressure gradient is approximately uniform across the estuary and drives an outward flow that is larger in the channel than on the shoals. In all of the parameter space the competition results in a net inflow on the shoals and a net outflow in the channel.