This article is from the Magic: The Gathering Rules FAQ, by Patrik Linell (pls@claymore.nu) with numerous contributions by others.
Basically, if an attacking creature with trample manages to kill
all of its blockers with damage "left over", the excess damage is dealt to
the defending player.
A creature with trample must assign lethal damage to all of its blockers
before it gets to assign any to the defending player, and it may assign
more if it wants to. For example, if a 7/7 with trample is blocked by a
2/2, the trampler must assign at least 2 damage to the blocker and can then
assign 5 damage to the defending player. The same creature blocked by a 1/1
and a 3/3 must assign 1 damage to the 1/1 and 3 damage to the 3/3 and can
then assign 3 to the defending player.
 
Continue to: