Rodney (Hunsaker) Halford appeals from two orders of the district court. The first order is the district court’s opinion on appeal from Halford’s conviction and sentence, wherein the court vacated the sentence and remanded to the magistrate for resentencing consistent with the parties’ plea agreement. The second order resulted from Halford’s petition for rehearing of the appellate order on the basis that his sentence was illegal. The district court, after a hearing, denied the petition and affirmed its original order on appeal. Halford seeks review by this Court. He raises only one issue on appeal, i.e., that the sentence imposed by the magistrate is illegal because it exceeds the maximum penalty prescribed for the crime of unenhanced misdemeanor driving under the influence of alcohol (DUI) to which he pled guilty. For the reasons stated below, we reverse the order of the district court and remand for resen-tencing before the magistrate in accordance with this opinion.
FACTS AND PROCEDURE
Halford was charged on May 20, 1991, with DUI in violation of I.C. § 18-8004(l)(a). He subsequently pled not guilty. Halford then moved on July 31, to change his plea to guilty to the unenhanced DUI charge as set forth in the uniform citation. Prior to accepting the plea, the magistrate advised Halford that, in light of his two recent, prior DUIs, he could have been charged with felony DUI. The magistrate also informed Halford that he could be sentenced to a maximum of one year in jail and a $2,000 fine, the penalty provided for an enhanced misdemeanor DUI under I.C. § 18-8005(4)(a), (b).
At sentencing on August 26, the magistrate considered the parties’ plea agreement whereby Halford was to be granted workout privileges on any sentence to be imposed. In response to a question from the magistrate, the prosecutor specifically denied any promise in the plea agreement that the DUI charge would be treated as a “first offense”; but he took no action to formally amend the complaint. Thereafter, the magistrate stated:
I’m not going to treat it as a first offense and if you want to withdraw the plea, you can — I’ll give you that opportunity to make that motion. But I’m not going to treat it as a first offense for a third DUI. I think he had two of them in one year, is that right?
When Halford elected not to withdraw his guilty plea, the magistrate imposed a sentence of one year in jail, a $2,000 fine, plus court costs, suspended driving privileges for one year following his release from jail and ordered Halford to an inpatient alcohol treatment program, after which he would entertain an application for workout privileges.
On Halford’s appeal from the judgment of conviction and sentence imposed by the magistrate, the district court issued a memorandum decision and order reversing and remanding, holding that the parties’ plea agreement had been breached by the magistrate’s failure to grant workout privileges. The district court, however, did not rule on the issue raised by Halford that his sentence was illegal in that he was sentenced for an enhanced DUI, even though he had only been charged with, and pled guilty to, an unenhanced DUI.
Halford filed a petition for rehearing with the district court, asking the court to reconsider the issue of whether his sentence was illegal. At the April 1, 1992, hearing on the petition, the court orally denied the petition and affirmed its original order on appeal. On April 2, 1992, Halford appealed from these two orders of the district court, raising only the issue of the illegality of his sentence.1 On April 3, *4131992, the district court entered an amended order staying the execution of that portion of the judgment which exceeds the maximum sentence for an unenhanced DUI.
ISSUE
In appealing from the district court’s appellate orders, Halford challenges that portion of his sentence in excess of six months’ incarceration, six months’ license suspension and a $1,000 fine. He contends that the sentence is illegal because the magistrate was compelled to impose only the penalty prescribed for an unenhanced DUI under I.C. § 18-8005(1).
DISCUSSION
On appeal from an order of the district court reviewing a determination made by a magistrate, we examine the record of the trial court independently of, but with due regard for, the district court’s intermediate appellate decision. State v. Godwin, 121 Idaho 491, 826 P.2d 452 (1992); State v. Schmidt, 121 Idaho 381, 825 P.2d 104 (Ct.App.1992). The question of whether the sentence imposed is illegal is a question of law freely reviewable by the appellate court. State v. Rodriguez, 119 Idaho 895, 811 P.2d 505 (Ct.App.1991), citing State v. Hale, 116 Idaho 763, 765, 779 P.2d 438, 440 (Ct.App.1989).
Halford argues that the magistrate erred in sentencing when he used Halford’s prior DUI convictions to “enhance” his punishment. He asserts that he pled guilty to an unenhanced DUI for which the statutory penalty is a maximum of six months in jail, a six-month license suspension and a fine of $1,000. Without an amendment to the citation, he argues, the magistrate’s sentencing discretion was bounded by the statutory penalty described in I.C. § 18-8005(1). We agree.
In this case, the citation accused Halford of “driving under the influence of intoxicants with a BAC of greater than .10 to wit: .15/.14” in violation of I.C. § 18-8004. The citation on its face had no designation that the offense charged was “enhanced” and contained no allegation of any particular prior conviction for DUI within the preceding five years, i.e., date of prior conviction, case number, county/state, etc. that was being used for enhancement purposes. Although the transcript reveals that the magistrate and Halford discussed Hal-ford’s prior convictions at the change of plea hearing, there is nothing in the record evidencing an oral amendment to the citation or the filing of an amended complaint by the state.
The broad discretion to charge an offense lies with the prosecutor. State v. Vetsch, 101 Idaho 595, 618 P.2d 773 (1980); State v. Gilbert, 112 Idaho 805, 736 P.2d 857 (Ct.App.1987). Furthermore,
The prosecutor is not obliged to present all charges which the evidence might support. The prosecutor may in some circumstances and for good cause consistent with the public interest decline to prosecute, notwithstanding that evidence may exist which would support a conviction.
ABA Standards, THE ADMINISTRATION OF CRIMINAL JUSTICE § 3.9 (1974). While denying that the plea agreement with Halford included an understanding that this case would be treated as a “first offense,” the prosecutor nevertheless did not move, either orally or in writing, to amend the citation/complaint with allegations of Halford’s prior DUIs for the purpose of “enhancement” of the charge thus subjecting Halford to increased penalties.
As in the case where the state seeks to punish a defendant as a persistent violator, the former convictions relied upon must be alleged in the indictment or information and proved at trial. See State v. Lovejoy, 60 Idaho 632, 95 P.2d 132 (1939). Similarly, in cases such as the one at hand, where the defendant is entering a plea of guilty to the charge, he must be informed of the prior DUI being used to “enhance” the offense. Thereafter, if the defendant enters a knowing and voluntary plea of guilty, he does so with an understanding of *414the nature of the charge and the penalty for the offense.
The colloquy of the magistrate at the change of plea hearing in this case cannot serve as a substitute for proper pleading or for a formal amendment alleging prior convictions to enhance the charge. It is also insufficient to show that the court amended the citation. Had there been an agreement between the prosecutor and the defendant that this would be an enhanced DUI, the prosecutor had the ability to move to amend the complaint orally at the time the plea was taken, citing the prior DUI being used for enhancement purposes. This would have allowed the magistrate the opportunity to question the defendant concerning the specific prior conviction being alleged and to make a determination that the defendant understood the nature of the charge as amended. The prosecutor, however, did not move to amend in this instance and, therefore, the citation for DUI was never “enhanced” by the state.
Misdemeanor Criminal Rule 3(d) provides that “[t]he court may amend or permit to be amended any process or pleading at any time before the prosecution rests ..., but no greater or different offense may be charged if substantial rights of the defendant are prejudiced.” The court in Lovejoy aptly expressed the concern that:
[i]f it were otherwise [a defendant] might enter his plea of guilty and then, after having been misled into waiving his right to trial, find that this plea, taken together with former convictions, makes him a persistent violator of law and renders him liable to punishment many times as great as that prescribed by statute for the offense, the commission of which, he has admitted by his plea.
Id. at 638, 95 P.2d at 134. Here, Halford entered his guilty plea to the crime with which he was charged, an unenhanced misdemeanor DUI. However, Halford received a sentence consistent with the penalty for an enhanced offense DUI under I.C. § 18-8005(4)(a), (b), (e). To uphold Hal-ford’s sentence, which exceeds the maximum incarceration, fine and license suspension for an unenhanced misdemeanor DUI would be contrary to law. See I.C. § 18-8005(1).
Our opinion is not to be read, however, to imply that the trial court, in sentencing a defendant, cannot consider the prior DUIs and driving record of that defendant. We hold only that in the proper exercise of its sentencing discretion, the trial court must confine itself to the maximum penalty for the offense to which the defendant pled guilty. The determination of whether a DUI offense is being prosecuted as an unenhanced or an enhanced misdemeanor is an issue separate and distinct from whether a defendant is a first offender or a repeat offender for sentencing purposes. The enhancement of a DUI offense is a matter within the purview of the prosecutor. The sentence imposed against the defendant, and the consideration of the defendant’s prior record, is within the purview of the court. As an example, a magistrate may not necessarily wish to sentence Halford, who has prior DUI convictions, to the same penalty, within the range prescribed by the statute, as a defendant with no prior contact with the law. In fashioning an appropriate punishment, the sentencing court should take into account all of the facts and circumstances surrounding the offense and the previous actions and character of the defendant. See generally, State v. Trowbridge, 95 Idaho 640, 516 P.2d 362 (1973).
We reverse the district court’s appellate decision and remand to the magistrate for resentencing consistent with this opinion.
WALTERS, C.J., and LANSING, J„ concur.. On April 2, 1992, in the magistrate division, Halford was resentenced on remand from the district court’s original order on appeal. The minutes of the hearing upon remand indicate that the magistrate determined, after reading the opinion of the district court on appeal, that the only matter to be addressed in the resen-tencing was to place Halford on work release in accordance with the terms of the plea agreement. The magistrate issued a Temporary Commitment, dated April 2, 1992, sentencing Hal-*413ford to "365 days in jail with work release from 6:30 a.m. to 8:30 p.m.”