When a creature dies, they leave the material plane. Unfortunately, when is a little unclear. I remember something from some book somewhere that specified souls lingered for a round or two or something like that, and that they were in the body if there was a body or otherwise in the general location. However, I also remember an answer on this site saying that there was a primary source argument defeating that. I'm having trouble tracking down any sources for this (I've checked the core rules but nothing seems particularly compelling, I've checked the epic level handbook, Dieties and Demigods (which has some stuff but nothing specific and campaign neutral), and the SRD). How long, according to the RAW, do souls linger before moving on (assuming the soul is the sort that does move on)?
When a creature dies, the creature's soul departs for its appropriate afterlife… unless it's like a creature that possesses the type elemental or outsider as such a creature's "soul and body form one unit" and "[w]hen… slain, no soul is set loose" (Monster Manual 313). Or unless it's like a creature that possesses either the type construct, deathless, or undead, which sees the creature destroyed at 0 hp. Other creatures—apparently even oozes and plants—have souls.
However, how long souls linger on the Material Plane after death is unclear.
A soul remains on the Material Plane anywhere from 1 or 2 rounds to a caster's caster level
Complete Divine on the Moment of Death says
When characters die, their souls… linger in the body for a round or two[, and i]f the corpse was completely destroyed, they linger at the location of death. The last breath spell [originally CD 167-8 but updated on Spell Compendium 130] works the way it does [i.e. if cast within 1 round of the subject's death, the subject suffers no level loss] because the soul of the deceased hasn’t gone anywhere yet (125).
But here Complete Divine implicitly contradicts the 8th-level Sor/Wiz spell soul bind [necro] (PH 281)—a core rules spell therefore from a primary source and taking precedence—, that says, "You draw the soul from a newly dead body[, and t]he subject must have been dead no more than 1 round per caster level." Hence the core rules say that souls loiter in the corpses for pretty much any amount of time… assuming an arbitrarily high caster level!
I suspect Complete Divine's author forgot about the soul bind spell when writing that section, focusing instead on the cool new spells present in Complete Divine. That's okay: exploring the game's contradictions is a great way to create plots. If everyone thinks that the soul departs 6–12 seconds after death, an ignorant but important figure may think himself safe after cutting a deal with a wizard that the wizard can have his soul 3 rounds after his death only to have the wizard (ahem) spirit away the figure's soul on round 3 or 10 or 15 using the spell soul bind! That important figure's family will need some adventurers to rescue that hapless fool's soul. I hear the family's offering a lot of treasure.
Based on the spell Revivify, the soul leaves the body in 6 seconds:
... the spell must be cast within 1 round of the victim's death. Before the soul of the deceased has completely left the body, ...
Leaving the body is not the same as leaving the material plane but, assuming the body is on the material plane, it sets a lower limit.