
443 Pa. Superior Ct. 479 (1995)
662 A.2d 658
COMMONWEALTH of Pennsylvania
v.
John WILLIAMS a/k/a Wayne Jacobs, Appellant.
Superior Court of Pennsylvania.
Submitted May 22, 1995.
Filed June 19, 1995.
Reargument Denied August 22, 1995.
*480 Mark D. Mungello, Blackwood, NJ, for appellant.
Kathy L. Echternach, Asst. Dist. Atty., Philadelphia, for Com., appellee.
Before ROWLEY, P.J., and TAMILIA and HESTER, JJ.
TAMILIA, Judge:
John Williams a/k/a Wayne Jacobs appeals from the July 27, 1994 judgment of sentence imposing a term of three and one-half (3½) to seven (7) years' imprisonment. The sentence followed a determination that appellant had violated his probation.
An annotated review of appellant's extensive criminal history[1] reveals the following. On February 15, 1990, appellant pled guilty to attempted theft by unlawful taking and was sentenced to eleven and one-half (11½) to twenty-three (23) months' imprisonment and to a consecutive term of three (3) years' probation. Appellant served the minimum sentence and was released on parole. Subsequently, on April 27, 1992, appellant was adjudicated in violation of his parole as a result of convictions for new crimes. Appellant's parole was revoked, he served the remainder of the 23 months under the original sentence, and his probation was continued. On July *481 27, 1994, appellant's probation was revoked following his conviction for involuntary manslaughter. Appellant was then sentenced to 3½ to 7 years' imprisonment, the maximum sentence allowable for appellant's February 15, 1990 plea of guilty to attempted theft by unlawful taking, a third degree felony. 18 Pa.C.S. § 1103(3). Appellant was allowed credit only for the time served on the violation of probation detainer and not for the cumulative 23 months which he had already served for the original offense. It is the failure to credit appellant with the 23 months already served which is the basis of his appeal.
Our scope of review on appeal from the judgment of sentence imposed following a probation revocation "is limited to the validity of the revocation proceedings and the legality of the final judgment of sentence." Commonwealth v. Beasley, 391 Pa.Super. 287, 570 A.2d 1336 (1990). Initially, we note that the trial court considered appellant's basis of appeal waived by his failure to raise it at the July 27, 1994 hearing. However, a challenge to the legality of a sentence is nonwaivable and may be considered sua sponte by our Court. Commonwealth v. Anderson, 434 Pa.Super. 309, 643 A.2d 109 (1994); Commonwealth v. Hollawell, 413 Pa.Super. 42, 604 A.2d 723 (1992).
The Legislature has established the manner by which credit for time served is to be computed. Specifically, 42 Pa.C.S. § 9760 provides:
§ 9760. Credit for time served
After reviewing the information submitted under section 937 (relating to report of outstanding charges and sentences) the court shall give credit as follows:
(1) Credit against the maximum term and any minimum term shall be given to the defendant for all time spent in custody as a result of the criminal charge for which a prison sentence is imposed or as a result of the conduct on which such a charge is based. Credit shall include credit for time spent in custody prior to trial, during trial, pending sentence, and pending the resolution of an appeal.

*482 (2) Credit against the maximum term and any minimum term shall be given to the defendant for all time spent in custody under a prior sentence if he is later reprosecuted and resentenced for the same offense or for another offense based on the same act or acts. This shall include credit in accordance with paragraph (1) of this section for all time spent in custody as a result of both the original charge and any subsequent charge for the same offense or for another offense based on the same act or acts.
According to appellant, this section requires that the 23 months he served on the unlawful taking sentence should be credited against the 3½ to 7 year term imposed on July 27, 1994. We are constrained to agree.
Pursuant to section 9760(1), "the criminal charge for which a prison sentence [was] imposed" was the charge of attempted theft by unlawful taking, to which appellant pled guilty on February 15, 1990. Thereafter, he served 11½ months pursuant to the February 15, 1990 adjudication and another 11½ months, the balance of the original sentence, pursuant to the adjudication of April 27, 1992. These sentences were both served on the underlying attempted theft offense. Likewise, the 3½ to 7 year term imposed on July 27, 1994 was the maximum sentence allowed by law for that offense. Thus, if appellant is not credited with the 23 months already served, his sentence for attempted theft by unlawful taking would be 65 months (or 5 years and 5 months) to 107 months (or 8 years and 11 months). Clearly, this sentence is illegal. See 18 Pa.C.S. § 1103(3).
Therefore, appellant must be credited with the 23 months already served. Also, as noted by the trial court at the July 27, 1994 hearing, appellant must be credited with the 8 months and 23 days he served on the probation violation detainer, from November 4, 1993 until July 27, 1994. In sum, the maximum sentence imposed on July 27, 1994 will be reduced by 31 months and 23 days making the new maximum sentence 52 months and 7 days. The new sentence, therefore, *483 based on the fact the minimum term can be no greater than half the maximum, is 26 to 52 months.
In accordance with this Opinion, the judgment of sentence is vacated and the case is remanded for imposition of the revised sentence of 26 to 52 months.
Jurisdiction relinquished.
NOTES
[1]  The record reveals that appellant, under various alias, has been arrested in excess of 50 times, has 25 convictions and 18 parole or probation violations.
