The New Zealand captain's 101st and last Test will be the second Test against Australia which starts in his home town, Christchurch, on February 20.
"I've loved my opportunity to play for and captain the Black Caps," the 34-year-old said.
McCullum said there was "something romantic" about finishing in front of his home crowd and he made the announcement now because his name would be missing when the New Zealand team is named soon for the World Twenty20 in India from March 8 to April 3.
AUSvNZ: Smith, McCullum praise day-night Test as success
"Ideally, I would have preferred to wait until after the Test in Christchurch to make this news public," he said.
"However, the schedule for naming the ICC World T20 squads means I couldn't have managed this without causing a lot of confusion and speculation, something I was keen to avoid."
The big-hitter, with a Test best 302 and co-holder of the world record of 100 Test sixes with Australian Adam Gilchrist, said now was not the time for him to dwell on his achievements.
"There's a time and place for reflection and that's at the end of your career," he said.
Dhoni, McCullum fetch million dollar deals in IPL draft
"For now, I'll be giving all my attention to helping the team focus on what's coming up over the next few weeks -- and making sure we're in the best possible shape for what's going to be a very challenging summer."
He added that giving testimony in the Chris Cairns match-fixing perjury trial in London last month had no impact on his decision to quit internationals.
Former teammate Cairns, who was cleared, has demanded McCullum explain why he chose to appear as a prosecution witness.
Kane Williamson, whose unbeaten century steered New Zealand to victory over Sri Lanka in the second Test in Hamilton on Monday, was immediately confirmed by New Zealand officials as captain for the World Twenty20.
McCullum has forged the best record of any New Zealand captain since taking over the leadership from Ross Taylor in December 2012.
Under his stewardship the Black Caps have won 11 and drawn 11 of 31 Tests.
His record as an one-day captain is a New Zealand best at 59.43 percent, which included leading his side the World Cup final this year.
McCullum made his international debut against Australia in 2002 and played his first Test against South Africa two years later.
In his 99 Tests, he has scored 11 centuries and is one of only 24 players and the only New Zealander to make a triple century.
His 6,172 Test run total is second best for a New Zealander behind Stephen Fleming.
In addition to sharing the record for the most Test sixes he holds the record for the most Twenty20 sixes with 91.
COMMENTS (1)
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ