2 of 2 added info provided by lord of ponies

Some badges (mostly the ones which can be awarded more than once) are awarded fairly quickly once you meet the criteria. Things like Nice Question, Enlightened, and the like. These are probably awarded from within the main system, typically triggered by voting activity.

Other badges (mostly the ones which can only be awarded once, like the specialist badges) are awarded by a background process which appears to run only once a day. According to TheTXI (comment below), this seems to happen at 0:00 UTC (at least on meta), but since we don't have an official word on this, it's hard to say whether it's the same for all sites or is consistent. However, it's safe to say that after 24 hours, if you still don't have your badge, something is amiss.