It depends. If the issue is taken to the Supreme Court (it sort of was with the Prop 8 trial, but there was legal issues keeping them from deciding gay marriage as a whole in that particular case) and they decide, it could be within a few years depending on how confident advocates are that the Supreme Court will invalidate same-sex marriage bans.
The federal government could also legalize it though congress but that would likely be challenged by states that have same-sex marriage bans and would go up to the Supreme Court, so basically same as above. Don't count on Congress passing a law like that anytime soon though, the Republicans are in the majority and their gerry-mandering in 2010 makes it tough for Democrats to take it back next year.
If we go state-by-state, like we have been doing, it could take a really long time. There will be a lot of states that will legalize it one way or another within the next few years, but southern states (+ Utah) will take a really long time to change their minds. Case-in-point: Alabama. They had an initiative to repeal their ban on interracial marriage in 2000. Note that interracial marriage was legal there since Loving v Virginia, the initiative was just to remove a law from their books that had been invalidated 30 years prior. There was literally no reason for anyone to vote against it and still
40% voted against it.