You can sneak attack when you are flanking or when your target is denied a dex bonus to DC.
Here are the major ways a target can lose its dexterity bonus in Pathfinder:
- If you, the attacker, are invisible.
- If you have successfully feinted in combat using the bluff skill (melee attacks only).
- If the target has the blinded condition (including the target being in "an area of darkness" if the target does not have the ability to see through/in the dark.
- If the target has the cowering condition.
- If the target has the flat-footed condition.
- If the target has the stunned condition.
- If the target has the pinned condition (not merely grappled).
- If the target has the helpless condition.
- If the target is running.
- If the target is using Acrobatics to move on narrow surfaces and uneven ground.
- If the target is climbing but does not have a climb speed.
- If the target is using the Escape Artist skill to squeeze through or into a space less than half its width.
- If the target is off balance when swimming (see underwater combat rules).
- If you are using the Improved Deadshot ability of the Crossbowman Fighter archtype.
- If you are using the Impromptu Sneak Attack ability of the Arcane Trickster.
- If you are using the Prescient Attack ability of the Magus.
- If you are using any of the following feats: Surprise Follow-Through feat (or its Improved version), Disengaging Shot, or other feats that work with feint.
You may note something very interesting in this list by its ommission. If the target has the blind condition, it loses its Dex bonus to AC. If you have the invisible condition, your targets lose their Dex bonus to AC. BUT there is no rule saying your target loses its dex bonus if you can see it and it cannot see you.
Why does it matter? If you are a rogue hiding behind an illusionary wall, it matters. If you are a dwarf with darkvision shooting at a target carrying a candle or torch, it matters. If you are a Waves Oracle with Water Sight shooting through mist at targets you can see who cannot see you, it matters. If you are using the sniping rules, it matters!
The question is: Does a target loses its dex bonus when attacked by creatures it cannot see? The rules in Pathfinder are ambiguous about this -- "If you cannot be seen" is not a condition mentioned as one that allows you to deny a target a dex bonus.
A DM might be guided by the following points:
1) The rules for Blindsense imply that the answer is yes:
I find these two points compelling, and I urge DMs to be swayed by them. Targets who cannot see a shooter should lose their Dex bonus to AC when fired on by that shooter. HOWEVER, so far as I can tell, RAW, your target does not lose its dex bonus just because it cannot perceive you. Stupid RAW.
"A creature with blindsense is still denied its Dexterity bonus to Armor Class against attacks from creatures it cannot see."
If a creature with Blindsense is denied its dex bonus against creatures it cannot see, then surely so too are creatures without Blindsense. Especially given the use of the word "still" in the rules.
2) A target who is blinded loses its dex bonus. If you have the invisible condition your target loses its dex bonus. Based on these, it is logical to rule that if the target cannot see/perceive you, it is denied its dex bonus.
Dungeons & Dragons 3.5 Ruleset Update: Note that there are some differences between the D&D 3.5 rules and the Pathfinder rules. First, as you may recall from this older screed on sneak attacks, in D&D 3.5, you lose your dex bonus if you are grappled. In Pathfinder, that's not sufficient: you also have to be pinned in PF to lose your dex bonus.