The homegrown Hammer and England Under-21 international has put pen to paper just before the start of pre-season training at Chadwell Heath.
Spence, 21, is hoping to become a regular part of the first-team at Upton Park after a loan spell at Bristol City last season and some late exposure to Premier League action.
"It feels good to be back. I was delighted the club wanted to tie me down for a longer period of time. It is cool to get it all sorted and I am looking forward to some good years ahead hopefully," he said.
And Spence is tipping the Hammers to bounce straight back to the top-flight at the first opportunity.
He added: "We have got Premier League quality throughout the team. That is going to be the main thing for us this season."