
617 N.W.2d 1 (2000)
STATE of Iowa, Appellant,
v.
Jason CORTEZ, Appellee.
No. 99-570.
Supreme Court of Iowa.
September 7, 2000.
Thomas J. Miller, Attorney General, Karen Doland, Assistant Attorney General, Richard R. Phillips, County Attorney, and Kerri Snyder and Alan Ostergren, Assistant County Attorneys, for appellant.
Linda Del Gallo, State Appellate Defender, and Tricia A. Johnston, Assistant State Appellate Defender, for appellee.
Considered en banc.
SNELL, Justice.
The State filed an application for discretionary review of a district court's construction of a sentencing statute. Review was granted, and we now hold the district court's interpretation of the statute was in error. The judgment is vacated, and the *2 matter is remanded for further proceedings.

I. Background Facts and Proceedings
On October 2, 1998, defendant, Jason Cortez, was charged with possession of marijuana. Cortez entered into an agreement with the State whereby he pled guilty to possession of a controlled substance (third offenseclass "D" felony). In exchange, the State consented to dismiss two alleged driving violations and to recommend a suspended five-year term of imprisonment. Conclusion of the accord was contingent upon its acceptance by the court. In reviewing the memorandum of plea agreement, the court, in writing, informed the defendant that if upon review of the presentence report the court decides to reject the plea agreement, that the defendant will be allowed the opportunity to withdraw the plea of guilty.
As stipulated, Cortez appeared before the bench and entered his plea. The court proceeded to engage defendant in a colloquy for the purpose of determining Cortez was aware of his rights, that these rights were voluntarily waived, that defendant understood the nature of the charge and the consequences of his plea, and that there was a factual basis to sustain a finding of guilt. Satisfied, the court accepted the defendant's plea of guilty to the charge of possession of a controlled substance third offense.
The court's acceptance of the plea agreement, however, was deferred pending further investigation. See Iowa R.Crim. P. 9(2) (court may accept or reject a plea agreement when offered, or it may defer its decision until receipt of a presentence report). At sentencing, the district court formally rejected the plea agreement on the ground it did not conform to the strictures of Iowa Code section 124.401(5) (1999). Thereunder, offenses are classified according to the nature of the controlled substance in question, and the frequency with which a defendant has been convicted for possession of illicit drugs. Section 124.401(5) provides as follows:
It is unlawful for any person knowingly or intentionally to possess a controlled substance unless such substance was obtained directly from, or pursuant to, a valid prescription or order of a practitioner while acting in the course of the practitioner's professional practice, or except as otherwise authorized by this chapter. Any person who violates this subsection is guilty of a serious misdemeanor for a first offense. A person who commits a violation of this subsection and who has previously been convicted of violating this subsection is guilty of an aggravated misdemeanor. A person who commits a violation of this subsection and has previously been convicted two or more times of violating this subsection is guilty of a class "D" felony.
If the controlled substance is marijuana, the punishment shall be by imprisonment in the county jail not more than six months or by a fine of not more than one thousand dollars, or by both such fine and imprisonment for a first offense. If the controlled substance is marijuana and the person has been previously convicted of a violation of this subsection in which the controlled substance was marijuana, the punishment shall be as provided in section 903.1, subsection 1, paragraph "b". If the controlled substance is marijuana and the person has been previously convicted two or more times of a violation of this subsection in which the controlled substance was marijuana, the person is guilty of an aggravated misdemeanor.
All or any part of a sentence imposed pursuant to this subsection may be suspended and the person placed upon probation upon such terms and conditions as the court may impose including the active participation by such person in a drug treatment, rehabilitation, or education program approved by the court.
*3 The court interpreted this statute to create two separate tracks of offenses, a misdemeanor track for marijuana, and a felony track for all other proscribed substances. To this end, the court held prior convictions under one track could not serve as a predicate for sentence enhancement under the other. By this logic a defendant convicted of possessing marijuana under section 124.401(5) for the first time would be guilty of a serious misdemeanor, regardless of whether that person had previously been convicted for possession of other controlled substances.
In the case at bar, Cortez was initially charged with a class "D" felony because the record indicated he had twice before been convicted for possession of illegal drugs, once for marijuana, and once for methamphetamines. In rejecting the plea agreement the district court decided that Cortez could only be sentenced under the marijuana track, that the prior conviction for possession of methamphetamine was irrelevant, and that based on one prior conviction for marijuana, defendant was only guilty of a serious misdemeanor.
Defendant was afforded an opportunity to enter a new plea through which Cortez admitted guilt with respect to possession of a controlled substance (second offense-serious misdemeanor). The State objected to the district court's interpretation of the statute, but conceded to Cortez's entry of a new plea. Defendant was sentenced to one year in the county jail (suspended), placed on probation for one year, and fined $1500. The State then filed an application for discretionary review proposing an alternative construction of the statute.

II. Discussion
We review a district court's interpretation of a statute for the correction of errors at law. State v. Eickelberg, 574 N.W.2d 1, 3 (Iowa 1997).
The State posits section 124.401(5) is only intended to grant leniency to those charged exclusively with marijuana related offenses. Once a defendant is convicted of a single offense involving other illegal substances, the State alleges all crimes committed prior or subsequent thereto could be used to enhance the offender's sentence under the stricter, felony track. This theory is based on the assumption it would be absurd to treat a defendant as a first time marijuana offender, when that person is guilty of antecedent convictions for possession of hard drugs. The State thus concludes Cortez's prior conviction for methamphetamines precludes the dispensation of leniency, thereby requiring he be found guilty of a class "D" felony.
We agree with the State's construction of the statute. The district court is in error; the law does not permit the punishment imposed. We have held that a sentence not permitted by statute is void. State v. Wiese, 201 N.W.2d 734, 737 (Iowa 1972). An illegal sentence is subject to correction at any time. Iowa R.Crim. P. 23(5)(a). This principle has been upheld even in cases in which the illegal sentence was more lenient than that allowed by law, and when correction of the sentence may result in an increase in sentence. See State v. Draper, 457 N.W.2d 600, 605-06 (Iowa 1990).
Defendant raises the issue of double jeopardy, however, he is not entitled to the protection afforded by this principle. We have previously indicated that a plea of former jeopardy cannot be based on a void sentence. State v. Sefcheck, 261 Iowa 1159, 1166, 157 N.W.2d 128, 132 (1968). This is generally true even if part of the illegal sentence has already been served. Id.; see also United States v. Davis, 561 F.2d 1014, 1017-18 (D.C.Cir. 1977).
In People v. Massie, 19 Cal.4th 550, 79 Cal.Rptr.2d 816, 967 P.2d 29 (1998), the Supreme Court of California held that double jeopardy did not attach where a guilty plea was invalidated. Massie, 79 Cal. Rptr.2d 816, 967 P.2d at 37-38. The court said:

*4 Ordinarily, jeopardy attaches when a defendant enters a plea of guilty, or when the court imposes sentence following the entry of that plea. Jeopardy does not attach when the plea is invalid, however. "[A]n unlawful guilty plea is null and therefore does not bar a second prosecution for the same offense. Thus, if a court lacks jurisdiction to accept a defendant's plea or if the plea violates any statute, then the plea and sentence will not bar reprosecution." (22 C.J.S. (rev.1989) Criminal Law, § 223, p. 272, fns. omitted.)
Id. (citations omitted); see also Cox v. State, 412 So.2d 354 (Fla.1982).
In the case at bar, Cortez was sentenced upon a guilty plea to a serious misdemeanor based on the trial court's erroneous construction of Iowa Code section 124.401(5) (1997). Judgment was entered, notwithstanding the sentence lacked statutory validity, as it was not supported by the underlying offense to which the defendant pled guilty. The judgment cannot be permitted to stand and must be vacated.
In State v. Iowa District Court, 464 N.W.2d 233, 236 (Iowa 1990), we considered a similar situation. The district court erred in ruling that a county jail did not constitute a "detention facility." Iowa Dist. Ct., 464 N.W.2d at 235. In so ruling, the court decided that the defendant could not be prosecuted under the original charge and then accepted a guilty plea to a lesser included offense, over the county attorney's objection. Id. at 236. We held that the proceedings in the district court were void, jeopardy did not attach, and the state was forced to prosecute for the higher offense. Id.
The State argues defendant should now be sentenced as provided for the commission of a class "D" felony. This is not permissible on the record because no judgment based on a guilty plea to a class "D" felony was ever validly entered. The entire proceedings surrounding the guilty plea were pervaded by the trial court's misconstruction of the meaning of the statute. Moreover, at the outset of the guilty plea colloquy, Cortez was advised he could withdraw his plea if the court rejected the plea agreement. In effect, the court did reject the plea agreement when it proceeded, over the State's objection, to accept a new guilty plea by Cortez to a serious misdemeanor offense, and sentenced him accordingly.
Because of the misinterpretation of the statute and void proceedings that followed, the case must be reversed and remanded. On remand the court is directed to vacate the void judgment based on the underlying serious misdemeanor offense and to allow the defendant to plead anew to the original charge, or to an amended charge if requested by the State and permitted by the trial court.
REVERSED AND REMANDED WITH DIRECTIONS.
All justices concur except NEUMAN, J., who takes no part.
