Its source is only 240 km ( 150 miles ) from the Atlantic Ocean , but the river flows away from the sea into the Sahara Desert , then turns near the ancient city of Timbuktu ( Tombouctou ) . From here , it goes southeast to the Gulf of Guinea . Its source is just 240 km ( 150 mi ) inland from the Atlantic Ocean , but the river runs away from the sea into the Sahara Desert , then takes a sharp right turn near the ancient city of Timbuktu ( Tombouctou ) and heads southeast to the Gulf of Guinea .