Minecraft wiki entry for Defense, associated text: T=trapdoor
B=opaque block
A=air
Layer 1
BBBB
TTTT
TTTT
BBBB
Layers 2 and 3
BBBB
AAAA
AAAA
BBBB
It's optional to add an overhang to defend from spiders. Also, to prevent mobs from walking on the side of the trapdoors, place blocks like fences or glass panes. This will make sure that the mobs go through the middle.