Cranie, who joined the Terriers in July 2015 following his release by Barnsley, was set to be out of contract at the end of the season.
The 30-year-old has made 50 appearances since signing for Town.
"I am delighted that we have agreed a deal to keep Martin at the club, as he is a very important player in our squad," head coach David Wagner said.
"I have always said that keeping our good players at the club is just as important as bringing new ones in, so I'm very happy."
Meanwhile, Wagner has revealed that on-loan Chelsea forward Kasey Palmer will be out for eight weeks with a hamstring injury.
The 20-year old suffered the injury in the first half of Town's 2-1 win over Leeds on 5 February.

Brain scans show EPO - used illegally by athletes to boost performance - may help infants when given after birth.
The study, published in the Journal of the American Medical Association, involved almost 500 babies born between 26 and 31 weeks in Switzerland.
The researchers are calling for wider trials of the hormone, which is already given to some babies to treat anaemia.
Erythropoietin is a hormone that stimulates production of red blood cells.
Synthetic EPO is used to treat conditions such as anaemia, where there are fewer red blood cells than normal.
It may also be given to premature babies to reduce the need for blood transfusions.
In the Swiss study, a team at the University Hospital of Geneva found that premature infants had a reduced risk of brain injury, as assessed by brain scans,  when given three doses of EPO shortly after birth.
Babies given EPO had lower rates of injury to both the brain's white matter (22% compared with 36% in the control group) and the grey matter (7% versus 19%).
"We found that the brains of the children who had received the treatment had much less damage than those in the control group, who had been given a placebo," said Dr Russia Ha-Vinh Leuchter, co-researcher of the study.
"This is the first time that the beneficial effect of the EPO hormone on the brains of premature babies has been shown."
The researchers are calling for wider clinical trials of EPO to see if it may help protect the brains of premature babies in the critical weeks after birth.
Dr Jane Hawdon, a consultant neonatologist at Barts Health NHS Trust, who was not involved with the study, said any treatment that may reduce long term problems in preterm babies warranted further review.
"We should note that the authors are not recommending immediate inclusion of this treatment into routine practice," she said.
"It is also important to note that the majority of preterm babies do not sustain significant brain injury."

It follows the release of a report into the disaster which resulted in the death of 96 fans.
Kelvin MacKenzie wrote the headline The Truth on the front-page story which ran four days later.
Trevor Hicks, of the Hillsborough Families Support Group, said it was "too little, too late".
In a statement Mr MacKenzie said: "Today I offer my profuse apologies to the people of Liverpool for that headline.
"I too was totally misled. Twenty-three years ago I was handed a piece of copy from a reputable news agency in Sheffield in which a senior police officer and a senior local MP were making serious allegations against fans in the stadium.
"I had absolutely no reason to believe that these authority figures would lie and deceive over such a disaster.
"As the prime minister has made clear these allegations were wholly untrue and were part of a concerted plot by police officers to discredit the supporters thereby shifting the blame for the tragedy from themselves.
"It has taken more than two decades, 400,000 documents and a two-year inquiry to discover to my horror that it would have been far more accurate had I written the headline The Lies rather than The Truth.
"I published in good faith and I am sorry that it was so wrong."
Huddersfield right-back Martin Cranie has signed a new contract to stay with the Championship club until 2018.
[NEXT_CONCEPT]
The hormone erythropoietin (EPO) could prevent brain injuries in very premature babies, a study suggests.
[NEXT_CONCEPT]
The former editor of the Sun has offered "profuse apologies to the people of Liverpool" for blaming fans for the Hillsborough tragedy.