[¶ 1] The State appeals from an order granting Shawn Ostafin’s motion to correct an illegal sentence on the ground that his waiver of any “good time” earned was illegal. We affirm the district court’s order that the original sentence was illegal, reverse that portion of the order allowing the withdrawal *617of the guilty plea, and remand for re-sentencing.
[¶ 2] On November 8, 1991, Shawn Ostafin entered pleas of guilty for the murders of his father, Roger Ostafin, and his step-mother, Rosemary Ostafin, both Class AA felonies. In accordance with a plea agreement, Ostafin was sentenced to serve two concurrent 17 year sentences at the State Penitentiary and waived any reduction in sentence for “good time” or good conduct under N.D.C.C. § 12-54.1-01. As a result, Ostafin’s sentence was a definite 17 years. The plea agreement, dated November 8, 1991, was in writing and signed by the State’s Attorney, the defense attorney and Shawn Ostafin.1
[¶3] Ostafin filed a motion to correct an illegal sentence with the District Court of Morton County on March 28,1996, which the State resisted. Counsel was appointed to represent Ostafin, and a hearing on the matter was held on August 25, 1996. At the hearing, Ostafin argued this Court’s decision in State v. Trieb, 516 N.W.2d 287 (N.D.1994) (Trieb II) was controlling, and as such, Os-tafin’s waiver of good time credits rendered his 1991 plea agreement illegal, resulting in an illegal sentence. Agreeing with Ostafin’s position that the sentence was illegal, the trial court gave Ostafin two choices: (1) withdraw his guilty plea and stand trial, or (2) continue the guilty plea and permit the judge to correct the sentence. Ostafin chose to withdraw his guilty plea. The State appeals from the court’s order issued on August 26, 1996, and dated October 1, 1996, permitting Ostafin to withdraw his plea of guilty.
[¶4] In his motion to correct an illegal sentence under Rule 35(a), N.D.R.CrimJP., Ostafin sought correction of the sentence so he could “collect all back, present, and future good time.” Ostafin’s motion did not request a withdrawal of his guilty plea. In response to the motion, the trial court interpreted Trieb II as requiring the court to offer a defendant the option of either withdrawing the guilty plea or asking the court to correct the illegal sentence. At the hearing on the motion, Ostafin indicated he would like to withdraw his guilty plea. We take this opportunity to clarify our decisions in Trieb II and State v. Trieb, 533 N.W.2d 678 (N.D.1995) (Trieb III).
I
[¶ 5] In Trieb II, this court held both the original sentence and the amended sentence were illegal sentences because a defendant cannot waive good time credits. Trieb, 516 N.W.2d at 291. This court stated: “[t]he sentencing court was outside its jurisdiction when it, in effect, guaranteed good time on a 30 year sentence by sentencing Trieb to 22 years, while placing limitations on accrual and application of good time.” Id. at 292. This court reasoned the deduction of good time credits from a sentence is a matter not within the discretion of the courts, but within the discretion of the penitentiary administration to encourage good conduct of prisoners. The legal maxim, “a law established for a public reason cannot be contravened by a private agreement,” supports our decision that a defendant cannot waive a right the legislature has given to prison administration to utilize for the purpose of inducing good behavior in prison. N.D.C.C. § 31-11-05(4). Further, there can be no waiver of statutory rights if such waiver would be against public policy. N.D.C.C. § 1-02-28. The legislative purpose of good time is to improve prison behavior and thereby improve overall prisoner morale and well being.
[¶ 6] The State urges this court to overrule its decision in Trieb II. The State, however, does not present any arguments not presented and decided in Trieb II. We are unpersuaded and affirm our decision in Trieb II.
*618II
[¶ 7] The State next argues the sentence given in Ostafin is distinguishable from the illegal sentence given in Trieb II, because Ostafin’s sentence, unlike Trieb’s sentence, neither approaches the threshold of a potential life sentence nor prohibits eligibility for parole. The State contends, because of these different facts, Trieb II does not apply to this case. Despite these differences in the sentences, however, the Ostafin sentence is still illegal under Trieb II because the sentence allowed the defendant to waive good time reduction in his sentence by plea agreement. A penitentiary prisoner must “earn” the monthly reductions for the sentence being served by “good conduct.” The statute does not authorize a prisoner to automatically “earn good time” by entering into a plea agreement. N.D.C.C. § 12-54.1-01. Our decision in Trieb II applies to this case, and we affirm the trial court’s determination that the sentence in State of North Dakota v. Shawn Allen Ostafin, Case No. 91-K-3235 was an illegal sentence.
III
[¶ 8] Finally, the State argues the trial court had the discretion to amend the sentence to correct it in such a manner so as to maintain the intent of the original plea bargain. We agree.
[¶ 9] In Trieb II, this court remanded the case to the trial court “to amend the sentence to allow for good time, or to allow Trieb to withdraw his guilty plea.” Trieb, 516 N.W.2d at 292 (emphasis ours). The trial court, instead of exercising its right to correct the illegal sentence, gave Trieb his choice and Trieb chose to continue his guilty plea. The trial court then re-sentenced him to thirty years, and allowed for good time credits, which, in effect, would result in a sentence of 22 years. At the sentencing hearing the trial court clarified that all parties understood “the sentence of 22 years is the equivalent of the 30 year requirement of the statute.” Trieb, 516 N.W.2d at 290.
[¶ 10] In Trieb III, this court was faced with the issue of whether the trial court’s sentence of Trieb on remand to thirty years in the state penitentiary with credit for time served and reinstatement of good time credit at the discretion of the entities granting the credit was within the intent of the original plea bargain. State v. Trieb, 533 N.W.2d 678 (N.D.1995). We stated: “the re-sentencing of Trieb to thirty years with the allowance of good time maintains the intent of the original plea bargain.” Id. at 681. We thus concluded the amended sentence was within the clear intent of the original plea bargain given the evidence in the transcript of the original sentencing hearing and the text of the sentence. Id.
[¶ 11] In Trieb III, this court summarized two schools of thought on the right of the sentencing court to correct an illegal sentence under Rule 35(a), N.D.R.Crim.P.2 State v. Trieb, 533 N.W.2d 678, 680-81 (N.D.1995) (quoting Christopher Vaeth, Annotation, Guilty Plea as Affected by Fact That Sentence Contemplated by Plea Bargain Is Subsequently Determined to Be Illegal or Unauthorized, 87 A.L.R.4th 384, 388 (1991)). The majority of states allow the defendant to withdraw a guilty plea if it is subsequently determined the sentence is illegal. Id. Some jurisdictions, however, have determined that “‘providing the defendant with an opportunity (sic) to withdraw the [guilty] plea may be unnecessary if the illegal sentence can be reconciled with the plea bargain or otherwise corrected so as to give the defendant the benefit of the bargain’.” Id., see, e.g., State v. Gourdin, 156 Ariz. 337, 751 P.2d 997 (Ariz.App.1988); Matter of Williams, 21 Wash.App. 238, 583 P.2d 1262 (1978). In Trieb III, Trieb chose to continue in his guilty plea and did not seek its withdrawal. Thus, this court did not embrace a particular school of thought to follow when defendant’s withdrawal of a plea may be unnecessary because the illegal sentence can be corrected so as to provide the defendant with the intent of the original plea bargain.
*619[¶ 12] In Trieb III, we held a sentencing court can correct an illegal sentence at “any time” under Rule 85(a), N.D.R.Crim.P. and can do so generally even if the correction results in a harsher sentence. Id. at 680; see also Rule 35(a), N.D.R.Crim.P. We pointed out in State v. Nace, 371 N.W.2d 129, 131 (N.D.1985), “American jurisprudence has a long history of correcting illegal or excessive sentences....” We have held correction of an illegal sentence involves a substantial right and an order denying correction of an illegal sentence is appealable. Nace, 371 N.W.2d at 131; State v. Gunwall, 522 N.W.2d 183 (N.D.1994).
[¶ 13] We do not analyze this case as a motion to withdraw a guilty plea under Rule 32(d), N.D.R.Crim.P. which states in part:
(1) The court shall allow the defendant to withdraw a plea of guilty whenever the defendant, upon a timely motion for withdrawal, proves that withdrawal is necessary to correct a manifest injustice.
Ostafin did not move to withdraw his plea of guilty under Rule 32(d), but rather moved to correct an illegal sentence specifically under Rule 35(a). Ostafin did not request he be allowed to withdraw his plea of guilty, but rather asked for a correction of his sentence so he could “collect all back, present and future good time.” Ostafin represented himself when he brought his motion, but had court appointed counsel at the motion hearing. He has never argued he should be allowed to withdraw his guilty plea “to correct a manifest injustice” under Rule 32(d)(1), N.D.R.Crim.P. We, therefore, do not examine this case under Rule 32(d) or preee-dent analyzing what criteria establish “a manifest injustice” thereunder.
[¶ 14] As previously noted, we upheld the trial court’s resentence of Trieb because the sentence “maintain[ed] the intent of the original plea bargain.” Trieb, 533 N.W.2d at 681 (N.D.1995).
[¶ 15] We conclude when a defendant brings a motion to correct an illegal sentence under Rule 35(a), N.D.R.Crim.P., the sentencing court should first determine whether the illegal sentence can be corrected in such a manner so as to preserve the intent of the original plea agreement and give the defendant that for which he bargained.3 Only if such modification of the original sentence cannot be done, should the defendant be given the opportunity to withdraw his guilty plea.
[¶ 16] Ostafin agreed to and expected to receive a determinate 17 year prison sentence in consideration of his waiver of “good time” reduction of his sentence. The sentencing court must modify the sentence to allow Ostafin to earn “good time” credits under N.D.C.C. § 12-54.1-01, but still serve two concurrent terms at least equal to the previously agreed upon 17 years. The corrected sentence must be reconciled with the intent of the plea agreement. If this cannot be accomplished, then the sentencing court must give Ostafin the opportunity to withdraw his guilty plea or persist in his guilty plea and be re-sentenced by the sentencing court.
[¶ 17] We remand to the sentencing court to determine whether the illegal sentence can *620be corrected so as to maintain the intent of the plea agreement and, if so, to re-sentence Ostafin consistent with our decision in Trieb III and this decision. Only if the court cannot modify the sentence to allow for “good time” and uphold the intent of the plea bargain, must Ostafin be allowed the opportunity to withdraw his guilty plea.
[¶ 18] VANDE WALLE, C.J., and MESCHKE, J., concur..The terms of the plea agreement were as follows:
“1. That the Defendant will be sentenced to serve a term of seventeen (17) years at the North Dakota State Penitentiary on each of the two charges of murder.
2.That those sentences shall be served concurrently.
3. That the Defendant’s sentence shall not be reduced for "good conduct” under section 12-54.1-01 NDCC.
4. That the Defendant shall receive credit for time served since December 1, 1990.”
. Rule 35(a), N.D.R.Crim.P. states:
"(a) Correction of Sentence. The sentencing court may correct an illegal sentence at any time and may correct a sentence imposed in an illegal manner within the time provided herein for the reduction of sentence.”
. Correcting this sentence would not be that difficult. N.D.C.C. § 12-54.1-01 states:
Offenders sentenced to the penitentiary or state farm shall be eligible to earn good conduct sentence reductions. Whenever two or more sentences have been imposed upon an offender, the aggregate of the several sentences shaE be the basis for determining the rate of reduction. Sentences may be reduced at the following rates:
[[Image here]]
5. Ten days per month on a sentence of ten years or more.
N.D.C.C. § 12-54.1-01 was amended in 1991 to state:
Except as provided under section 12.1-32-09.1, offenders sentenced to the penitentiary or any of its affiliated facilities are eligible to earn sentence reductions based upon performance criteria established through penitentiary rules. Performance criteria includes participation in court-ordered or staff-recommended treatment and education programs and good work performance. WhEe incarcerated in the peniten-tiaty or any of its affiliated facilities, an inmate may earn five days good time per month except for any sentence where the incarceration time is six months or less.
Since Ostafin’s crime was committed before 1991 and the amendment of N.D.C.C. § 12-54.1-01, the apphcable good time would be computed at the rate of ten days per month.