
779 P.2d 438 (1989)
116 Idaho 763
STATE of Idaho, Plaintiff-Respondent,
v.
John Stewart HALE, Defendant-Appellant.
No. 17819.
Court of Appeals of Idaho.
September 7, 1989.
*439 John S. Hale, Boise, pro se.
Jim Jones, Atty. Gen., Michael A. Henderson, Deputy Atty. Gen., Boise, for plaintiff-respondent.
PER CURIAM.
This is an appeal from a district court's order denying relief on a motion under I.C.R. 35 to correct a sentence of incarceration imposed in a felony case. In his motion, John Hale alleged that he had not been given proper credit for a period of incarceration preceding his commitment to the Board of Correction on a three-year sentence for possession of a controlled substance. The district court found that Hale had received all credit to which he was entitled. We agree and affirm.
The following background appears in the record. Hale was arrested and incarcerated in Bonner County upon a charge of manufacturing methamphetamine and of conspiring to violate the Controlled Substance Act (Case I). Fifteen days later, he was released on bond. According to Hale's bondsman, the bond was posted "with the express stipulation that the Defendant not be rearrested for anything other than a minor traffic violation for the term of the bond." Approximately three weeks later, Hale was arrested in Kootenai County on charges of aggravated battery and of manufacturing a controlled substance (Case II). These latter charges were unrelated to the prosecution in Case I. The district court in Case I entered an order allowing the surety company which had posted Hale's bail bond to withdraw its bond and exonerated the surety from the responsibility of assuring Hale's court appearance. Hale was unable to post bond in Case II, so he remained in jail in Kootenai County.
Eventually, Hale pled guilty in Case I to an amended charge of possession of a controlled substance. He was sentenced to the custody of the Board of Correction for a fixed, three-year term.[1] Hale was given fifteen days credit on that sentence for the period of incarceration he served in the Bonner County jail prior to being released on bond.
Shortly thereafter, Hale also pled guilty in Case II to a charge of manufacturing a controlled substance.[2] Because that offense occurred after the effective date of the Unified Sentencing Act, he received an eight-year sentence with a minimum confinement period of two years. Hale received 216 days of presentence credit for the jail time he served in Kootenai County while awaiting disposition of Case II. The sentence in Case II was ordered to be served concurrently with the sentence imposed in Case I.
Hale filed a motion with the district court in Bonner County, seeking correction of the sentence in Case I. He asserted that he should have received credit toward his sentence for time spent in the Kootenai County *440 jail. The district court denied Hale's request. The court held that Hale's incarceration in the Kootenai County jail was for an offense other than the one for which he was sentenced in Case I and, therefore, Hale was not entitled to credit in that case for the Kootenai jail time.
On appeal, Hale contends that the district court's denial of presentence incarceration credit was error. The thrust of Hale's motion to correct his sentence is that the sentence is illegal to the extent that he was not given full credit in accord with I.C. § 18-309 for presentence incarceration.[3]See Law v. Rasmussen, 104 Idaho 455, 660 P.2d 67 (1983). Under I.C.R. 35, an illegal sentence may be corrected at any time. Also, in an appeal from the denial of a motion under Rule 35 to correct an alleged illegal sentence, the question whether a sentence imposed is "illegal" is one of law freely reviewable by the appellate court. See United States v. Fowler, 794 F.2d 1446, 1449 (9th Cir.1986), cert. denied, 479 U.S. 1094, 107 S.Ct. 1309, 94 L.Ed.2d 153 (1987), citing 3 C. WRIGHT, Federal Practice and Procedure (Criminal) § 588 (2d ed. 1982 & Supp. 1989) (applying comparable federal rule 35).
We are not persuaded that Hale's sentence in the Bonner County case was illegal. As noted by the district court, Hale was not incarcerated in Kootenai County upon "the offense ... for which judgment was entered" in Case I. He was incarcerated in Kootenai County upon an offense committed in that county after he was released, on bond, from custody in Bonner County. Hale's bond in Case I was withdrawn and exonerated only after his arrest in Kootenai County. Thereafter he was unable to post a bond in either case and he remained incarcerated in Kootenai County on charges in Case II.
An entitlement to credit under I.C. § 18-309 depends upon the answer to a simple inquiry: was the defendant's incarceration upon the offense for which he was sentenced? If a particular period of confinement served prior to the imposition of sentence is not attributable to the charge or conduct for which a sentence is to be imposed, the offender is not entitled to credit for such confinement; neither does the sentencing judge err by denying credit under such circumstances. See Schubert v. People, 698 P.2d 788 (Colo. 1985); citing, In re Rojas, 23 Cal.3d 152, 151 Cal. Rptr. 649, 588 P.2d 789 (1979); People v. Brents, 115 Ill. App.3d 717, 71 Ill.Dec. 222, 450 N.E.2d 910 (1983); State v. Calderon, 233 Kan. 87, 661 P.2d 781 (1983); Handley v. Commonwealth, 653 S.W.2d 165 (Ky. Ct. App. 1983); Commonwealth v. Foley, 15 Mass. App. 965, 446 N.E.2d 737 (1983); and State v. Eugene, 340 N.W.2d 18 (N.D. 1983). Because Hale's incarceration in Kootenai County was not for the offense for which he was sentenced in Bonner County, the district court did not err in refusing to give Hale credit in Case I for any time served while awaiting disposition of the charges in Case II.[4]
Hale also claims that his sentence is a violation of his equal protection and due process rights embodied within the United States Constitution and the Idaho State Constitution. For Hale to assert a valid *441 equal-protection claim he must demonstrate that his treatment was a classification not rationally related to a legitimate government interest. State v. Reed, 107 Idaho 162, 686 P.2d 842 (Ct.App. 1984). Broadly speaking, equal protection guarantees that all people similarly situated are to be treated in a similar manner. State v. Hayes, 108 Idaho 556, 700 P.2d 959 (Ct.App. 1985) (review denied). Idaho Code § 18-309 is designed to afford credit to defendants for time served prior to sentencing and to allow the courts to determine an appropriate penalty to be levied against the guilty defendant. Hale has failed to demonstrate that he is being treated unfairly or unequally by the application of this law. Hale served time and received credit in Case I for fifteen days on charges stemming from Bonner County. After being released on bail he committed a separate crime and was incarcerated for it in the Kootenai County jail for 216 days for which he received credit in Case II. Hale received full credit for every day he was incarcerated prior to his sentencing. We hold that Hale was not denied equal protection or due process.
Finally, Hale argues that he is entitled to additional credit on the Bonner County sentence in Case I because I.C. § 18-309 is ambiguous and such ambiguity should be resolved in favor of lenity. State v. McKaughen, 108 Idaho 471, 700 P.2d 93 (Ct.App. 1985). However, the rule of lenity is inapposite here. We perceive no ambiguity. Moreover, lenity does not require complete disregard of the clear purpose of a legislative enactment. See, Schubert v. People, 698 P.2d 788 (Colo. 1985). As stated, the evident purpose of the statute is to give credit for time spent in jail on a related offense. Had Hale not committed the second offense, he would have remained free on bail. However, he now contends that his incarceration on the second unrelated offense should be credited to the first offense. Granting Hale credit for time served, as a result of intentional criminal conduct he should have known would jeopardize his freedom, is contrary to the obvious policy of the penalizing statutes. Allowing individuals to receive credit for unrelated offenses could result in defendants stockpiling presentence incarceration credits. This could lead to the anomalous result of reducing the effective penalty for a crime if it is followed by another crime. In any event, given the plain and unambiguous meaning of I.C. § 18-309, we hold that the doctrine of lenity is inapplicable.
We conclude that the calculation of presentence incarceration credit was proper and that Hale's sentence was not illegal. Accordingly, the order of the district court, denying Hale's motion to correct his sentence, is affirmed.
NOTES
[1]  This offense was alleged to have occurred in 1986, before the Unified Sentencing Act, I.C. § 19-2513, became effective on February 1, 1987. Hale was given a fixed sentence under former I.C. § 19-2513A (repealed by the Unified Sentencing Act; 1986 Idaho Sess. Laws ch. 232, § 4, p. 640).
[2]  We do not have before us the complete record of the Kootenai County case. Evidently, the aggravated battery charge was dismissed as part of a plea bargain in exchange for Hale's plea to the drug charge.
[3]  Section 18-309, Idaho Code, provides, in part:

In computing the term of imprisonment, the person against whom the judgment was entered, shall receive credit for any period of incarceration prior to entry of judgment, if such incarceration was for the offense or an included offense for which the judgment was entered. [Emphasis added.]
[4]  Our conclusion is not inconsistent with language appearing in Matthews v. State, 113 Idaho 83, 741 P.2d 370 (Ct.App. 1987). There, a defendant was incarcerated before trial on two charges pending in the same court. He ultimately received consecutive sentences on the charges, and he requested credit on both sentences for his prejudgment confinement. We held that the credit was properly applied only to the first sentence, noting that "[h]ad the sentences been concurrent, Matthews' point would have been well taken." Id. at 87, 741 P.2d at 374. Hale now contends that our language entitles him to the credit he seeks because his sentences are concurrent. This contention overlooks the fact that in Matthews there was a single period of prejudgment incarceration on two charges pending in the same court; here, there were two distinct periods of prejudgment incarceration on separate charges pending in different courts. This distinction is critical under I.C. § 18-309.
