
93 P.3d 1254 (2004)
2004 MT 178
STATE of Montana, Plaintiff and Respondent,
v.
Raymond E. EVERT, Defendant and Appellant.
No. 03-152.
Supreme Court of Montana.
Submitted on Briefs May 19, 2004.
Decided July 6, 2004.
For Appellant: Chad Wright, Appellate Defender, Helena, Montana.
For Respondent: Mike McGrath, Attorney General; Jim Wheelis, Assistant Attorney General, Helena, Montana, Ed Corrigan, County Attorney, Kalispell, Montana.
Justice W. WILLIAM LEAPHART delivered the Opinion of the Court.
¶ 1 Raymond E. Evert (Evert) appeals the sentence the District Court imposed upon resentencing. We reverse and remand.
¶ 2 The issues on appeal are restated into the following single issue: Did the District Court have jurisdiction to resentence Evert?

Factual and Procedural Background
¶ 3 Evert pleaded guilty pursuant to a plea agreement to the offense of sexual assault, a felony. In September of 1997, Evert was sentenced to 65 years at the Montana State Prison with 15 years suspended. He was also ordered ineligible for parole until he completed all phases of the prison's sex offender treatment program.
*1255 ¶ 4 In June of 1998, Evert filed a pro se petition for postconviction relief which alleged numerous claims related to his guilty plea and sentencing. The Flathead County Attorney's Office (the County) responded to his petition. When the court did not hold a hearing regarding his petition, Evert filed a petition for writ of supervisory of control in April of 1999. This Court then ordered the County and the Attorney General to file a response to the petition for writ of supervisory control. The District Court subsequently ordered that a public defender be appointed to represent Evert.
¶ 5 Although the record indicates a public defender then began to act on Evert's behalf, the record also indicates that communication between the public defender's office and Evert was lacking. Evert filed a pro se motion to supplement his petition for postconviction relief in September of 1999. After court continuances and appointment of a different public defender to assist Evert, the parties notified the court that they had reached an agreement on Evert's petition for postconviction relief. Evert's counsel then summarized the agreement for the court. In sum, in exchange for receiving a new sentence by the District Court, Evert withdrew his postconviction petition, waived his right to appeal the amended sentence, and waived his right to file any further postconviction petitions based on the new sentence.
¶ 6 Evert's counsel stated that Evert understood that because he originally pleaded guilty, he could be sentenced to life in prison, or not less than two years or more than 100 years in prison, and fined up to $50,000. Deputy County Attorney Ed Corrigan then stated
that by statute and by numerous rulings by the Supreme Court, that a district court judgment, once it has been passed, is basically set in stone. However, it's always been my practice  and also been the practice of this Court  that if a Defendant who has previously been sentenced appears before either myself or you and shows good cause as to why his sentence should be amended, generally mitigated, we don't object to that.
We don't hold firm to the technicalities of the statute or the Supreme Court rulings. The thought being if a person has made some progress in his life and is doing better, and is no longer the threat that he was perhaps four or five years ago, that some consideration should be given for those efforts that he's made.
¶ 7 The progress that Evert made in prison was then discussed. Evert also testified on his own behalf. At the conclusion of the proceedings, the court, upon motion, and based upon the representations and testimony of Evert, dismissed the petition for postconviction relief. The matter was then continued to be reset upon a motion, not the postconviction relief petition, but, as the court stated, "whatever you're going to call it, for a hearing on the request for modification of the sentence."
¶ 8 In November of 2002, Evert and his counsel appeared for a hearing on Evert's request that his sentence be modified. The order setting this hearing was entitled "Order Requesting Final Determination of Post-Conviction Relief for the Defendant Raymond Earl Evert" even though, as previously established, Evert's claims for postconviction relief had been dismissed. Prior to the hearing, Evert filed letters, progress reports, and information regarding his progress while incarcerated.
¶ 9 At the conclusion of the hearing, the court ordered that Evert be incarcerated in the Montana State Prison for 60 years with 20 years suspended. He was to receive good time credit for the time served prior to sentencing and the time served since. In an Amended Judgment and Sentence, filed January 24, 2003, the court stated it considered Evert's testimony at the hearing, the evidence presented, the nature of his offense and his criminal history, his 1997 Pre-Sentence Investigation and Sex Offender Treatment Evaluation, the apparent progress in treatment he made while at the prison, and the recommendations of counsel before it entered its sentence. In addition to the previously-mentioned sentence, the court also ordered Evert "be given credit for 228 days served in the Flathead County Detention Center pending final disposition in this matter." *1256 Evert was also to be given credit for the time he served as a prison inmate from September 4, 1997, through November 15, 2002. He remained ineligible for parole until he completed the prison's sex offender treatment program with the exception that "[i]f, upon completion of Phase II of that program, his treatment providers believe he can safely complete sex offender treatment and Aftercare in a community setting, this restriction [on his parole eligibility] will no longer apply." Evert's counsel was subsequently allowed to withdraw from Evert's case. Evert then attempted to proceed pro se on his petition for postconviction relief but later requested and received the assistance of counsel.
¶ 10 On appeal, Evert claims that he "waived numerous potential claims in postconviction for the opportunity to be re-sentenced." He contends that in the new sentencing proceeding, the court "mistakenly told him that he would be eligible for parole after he served one-quarter of his sentence less good time." Evert claims that because the court incorrectly advised him regarding this eligibility, he "did not fully understand the consequences of waiving his postconviction claims." Thus, he claims the standard of review that applies should be that for evaluating the voluntary nature of guilty pleas. He requests that because a waiver of legal rights cannot be based on a fundamental mistake, this Court should modify the sentence and judgment to grant his immediate parole eligibility to reflect Evert's understanding that good time would be applied to parole eligibility.
¶ 11 The State claims that the authorities Evert cites do not apply in the present case because they concern "information about sentencing given the defendants before they entered guilty pleas." The State contends that "[t]he record is devoid of any suggestion that Evert would receive good time against his parole eligibility until after he had waived his postconviction petition and presented his evidence and arguments." The State claims that the record does not support the argument that Evert relied on a specific parole eligibility date before he entered his guilty plea. Instead, the State points out that Evert acknowledged several times that he could receive the maximum allowable sentence. The State also maintains that the standard of review that should be applied in this case is whether Evert's sentence (upon resentencing) was legal.

Discussion
¶ 12 Did the District Court have jurisdiction to resentence Evert?
¶ 13 The issue of jurisdiction has not been raised by the parties in this case. However, it is essential a court have subject matter jurisdiction before acting. Lack of subject matter jurisdiction cannot be waived. Sage v. Gamble (1996), 279 Mont. 459, 463, 929 P.2d 822, 824. Lack of subject matter jurisdiction may be raised at any stage of a judicial proceeding by a party or sua sponte by the court. Sage, 279 Mont. at 463, 929 P.2d at 824. Therefore, we address the issue of subject matter jurisdiction sua sponte. Sage, 279 Mont. at 463, 929 P.2d at 824.
¶ 14 Jurisdiction is defined by law. Vannatta v. Boulds, 2003 MT 343, ¶ 16, 318 Mont. 472, ¶ 16, 81 P.3d 480, ¶ 16. Jurisdiction cannot be conferred by consent of the parties or the court. Vannatta, ¶ 16. Once a valid sentence is imposed, the district court lacks jurisdiction to modify that sentence absent specific statutory authority. Gilbert v. State, 2002 MT 258, ¶ 17, 312 Mont. 189, ¶ 17, 59 P.3d 24, ¶ 17. Additionally, a court cannot reserve the right to change a sentence at a later time. Gilbert, ¶ 17.
¶ 15 At the time Evert filed his petition for postconviction relief, § 46-18-117, MCA (1997), provided that a court may modify or "correct an erroneous sentence or disposition at any time and may correct a sentence imposed in an illegal manner within 120 days after the sentence is imposed or after remand from an appellate court." Once a petition for postconviction relief is filed and a hearing held, a court may find in favor of the petitioner and then "enter an appropriate order with respect to the judgment or sentence in the former proceedings and any supplementary orders as to reassignment, retrial, custody, bail, or discharge that may be necessary and proper." Section 46-21-201(6), *1257 MCA. The court may also alternatively find for the prosecution, and the petition then must be dismissed. Section 46-21-201(6), MCA.
¶ 16 A plain reading of § 46-18-117, MCA (1997), clearly provides that a court only has jurisdiction to modify an erroneous or illegal sentence. Neither Evert nor the State alleges that Evert's original sentence was illegal or erroneous. His original sentence was for 65 years in prison with 15 years suspended. This is within the parameters provided by § 45-5-502, MCA, pursuant to which Evert was sentenced. The record reflects that rather than proceeding with a postconviction hearing on Evert's claims, Evert and the County chose to enter a stipulated agreement which would allow him to be resentenced on the original charge. The court honored this agreement and subsequently conducted the resentencing in November of 2002, approximately five years after Evert was originally sentenced in September of 1997.
¶ 17 Jurisdiction is defined by law. Vannatta, ¶ 16. Neither the State nor Evert has cited any statutory authority which authorized the District Court to exercise continuing jurisdiction to review and modify Evert's original sentence. The court entered a final judgment and, absent a showing of error or illegality of the sentence, the court lacked jurisdiction to modify this sentence. Section 46-18-117, MCA (1997). Although both the County and Evert agreed to the resentencing, jurisdiction cannot be conferred by consent. Vannatta, ¶ 16. Accordingly, the judgment entered pursuant to the resentencing is invalid.
¶ 18 Once Evert filed his petition for postconviction relief, the court had jurisdiction to conduct a hearing and either decide the matter in favor of Evert (entering an appropriate order or judgment with respect to the previous proceedings) or in favor of the County (thus dismissing Evert's claims). Section 46-21-201(6), MCA. The court did neither. Instead, the court resentenced Evert approximately five years after his original sentence was pronounced. No authority has been provided nor can this Court find any which would permit this resentencing. The District Court's resentencing of Evert is reversed. Evert's original sentence is reinstated and the postconviction claims that he waived in exchange for resentencing are also reinstated.
¶ 19 The laws of the State of Montana are written to ensure that justice is served and the well-being of society and individuals is safe-guarded. Contrary to the County Attorney's pronouncement to the District Court that "we don't hold firm to the technicalities of the statute or the Supreme Court rulings," adherence to the legislative enactments and the decisions of this Court is not a matter of convenience or prosecutorial preference. No court or officer of the court has the prerogative of circumventing or modifying the procedures established by law. We reverse and remand for consideration of Evert's petition for postconviction relief.
JAMES C. NELSON, JOHN WARNER, JIM REGNIER and JIM RICE, JJ., concur.
