delivered the opinion of the Court.
On April 12, 1954, the plaintiff, after having pleaded guilty, was sentenced by the Superior Court to serve from 1 to 5 years in the penitentiary for the crime of Burglary in the First Degree.1
While he was serving said sentence, the plaintiff escaped twice from the District Jail of Mayagüez, in February and October 1954. Upon being prosecuted for two violations of § 152 of the Penal Code (escape), he pleaded guilty and was sentenced on October 4, 1954, to serve from 1 to 3 years in the penitentiary, and on November 12, 1954 to serve from 1 to 2 years in the penitentiary.
*670Four years after the sentence in the case of Burglary in the First Degree was rendered, a petition for Habeas Corpus was filed by the accused alleging that said burglary had been committed by day and not at nighttime and, therefore, the crime committed was burglary in the second degree (a misdemeanor) . The hearing for this petition was held on August 29,1958. The prosecutor acquiesced and after the court had set aside the sentence, the accused pleaded guilty of burglary in the second degree and was sentenced to 2 years in jail.
On September 23, 1958 the accused filed another petition for Habeas Corpus alleging that the sentences rendered for his escape were null because the court lacked jurisdiction when they were rendered and because if he did commit a crime, it was a violation of § 152 in its modality of misdemeanor. Said petition was denied and the plaintiff makes in this Court the following contentions:
1 — “The court erred in concluding that the petitioner was legally detained in prison on the dates in which he committed the crimes for escape, for which he was sentenced on counts G-54-138 and G-54-206 and that he had no right to escape from jail.”
2 — That the sentence for Burglary in the First Degree having been set aside and the accused sentenced for the misdemeanor of burglary in the second degree, the sentences for escape do not conform to law; that the proper thing to do with said sentences is what was done with the sentence of burglary in the first degree, that is, to set them aside and arraign him for the misdemeanor of escape and impose the penalty entailed by the degree of that offense.
The first error was not committed.
Section 152 of the Penal Code (33 L.P.R.A. § 509) provides that:
*671Ҥ 509. Escape from prison
“Any person under lawful custody who shall escape while being held in restraint, or during the pendency of an appeal, or while serving sentence, shall be punishable on summary order of the Superior Court of Puerto Rico in accordance with the following penalties: (a.) if while held in restraint, he shall be guilty of a misdemeanor, and be subject to imprisonment in jail for a term of not less than one month nor more than two years; (6) if serving sentence or during the pendency of an appeal for a felony, he shall be guilty of a felony and be subject to imprisonment in jail for a term of not less than one year no more than ten years; (c) if serving sentence or during the pendency of an appeal for a misdemeanor, he shall be guilty of a misdemeanor and be subject to imprisonment in jail for a term of not less than one month nor more than five years.
“This penalty shall be additional to the sentence imposed on him for the other offense, or to the one he is serving, as the case may be; Provided, That such penalty shall not be concurrent with any other.”2
Essential elements required for this offense are:
1 — That the person be under legal custody; and
2 — At the time of his escape he be (a) in prison awaiting trial, (6) or his appeal pending, or (c) serving his sentence.
Thus, any person who escapes from a place, such as jail, where he is under legal custody, commits the crime of escape. Escaping from legal custody, rather than escaping from a place of confinement, constitutes the essence of the crime. 3 Anderson, Wharton’s Criminal Law, § 1373; 1 Burdick, The Law of Crime, § 306; State v. Lewis, 19 Kan. 260, 27 Am. Rep. 113. The reversal of a sentence on appeal is no defense in a prosecution for escape of the accused if said appeal is pending. Moore v. Commonwealth, 301 Ky. 851, 193 S.W.2d 448. Even though the person is imprisoned by virtue of a sentence that may be reversed or set aside on *672appeal or in a habeas corpus proceeding, if he escapes, he commits the crime of escaping since the original sentence is valid until it is reversed or set aside. Commonwealth v. Ashe, 142 Pa. Supp. 403; 17 A.2d 224. See also, Stinehagen v. Olson, 145 Neb. 653, 17 N.W.2d 674; and the annotations in 15 L.R.A. 90, 56 A.L.R. 667 and 163 A.L.R. 1137, 70 A.L.R.2d 1430; Copeland v. Manning, 109 S.E.2d 361; People v. Jones, 329 P.2d 37.
There are cases in which the person detained or imprisoned is not under legal custody. Thus, for example, it has been decided that when the imprisonment is illegal, and this in itself is a crime, the escape by the accused is not a crime. People v. Ah Teung, 92 Cal. 421, 28 Pac. 577; People v. Clark et al., 69 Cal. App. 520, 231 Pac. 590; State v. Hatfield, 66 Wash. 9, 118 Pac. 893. However, a great difference exists between an imprisonment without any process and wholly without authority of law and an imprisonment under a process which is simply irregular in form. People v. Ah Teung, supra. Not always may a person erroneously imprisoned escape without any punishment. On the contrary, the ordinary case is where his imprisonment, although erroneous, originates from such sources as to make it incumbent on the prisoner to ask the competent court to so adjudge his erroneous imprisonment, and in the appropriate cases, to put and end to said imprisonment by judicial order. If in such cases the prisoner chooses to free himself by escaping from prison, he commits the crime for escape. People v. Hinze, 217 P.2d 35; Aderhold v. Soileau, 67 F.2d 259; Bayless v. United States, 141 F.2d 578; People v. Armstrong, 10 West Cal. Reptr. 618 (1961).
In brief, it might be said that the courts have laid down two rules regarding the crime of escape, to wit:
1 — When the defendant has been imprisoned wholly without authority or under process that is entirely illegal, the defendant’s right to liberty is absolute and he may take whatever steps are *673necessary to gain the freedom without committing the crime of escape.
2 — In all other cases, not enumerated in the aforesaid rule,, there is no justification for an escape.
The first rule gets support from the individual’s right to his freedom and the constitutional guarantee that that right shall not be taken from him without due process of law. The second rule is based on the theory that the individual should submit to the law and not take it in his own hands and that in order to attain freedom he must resort to the proceedings established by law. See 24 So. Cal. Law Rev. 114.3
In the case at bar the difference between the time in which he actually committed the crime and that alleged in the accusation, does not render the sentence void for lack of due process of law. Therefore, we conclude that in the two occasions in which the petitioner escaped from the District Jail in Mayagiiez, he was under legal custody and therefore he violated § 152 of the Penal Code.
Nor do we agree with the petitioner in his second contention. We have said that the petitioner was under legal custody serving a sentence for a felony when he escaped from the District Jail of Mayagiiez. Section 152 of the Penal Code provides that when the accused is serving a sentence or during the pendency of an appeal for a felony he shall be guilty of a felony subject to imprisonment in jail for a term of not less than one year nor more than ten years. We agree with the Attorney General in that the keystone to determine whether the crime of escape is a felony or a misdemeanor lies in-the nature of the confinement at the time of the escape. The-nature of the crime does not depend on future contingencies *674of the sentence causing the accused’s imprisonment. Therefore, it is no defense in the crime of escape that the information by virtue of which he was arrested be dismissed, that the evidence for said sentence be insufficient or that he be acquitted on said evidence. Nor is the reversal of the conviction on appeal a defense. 3 Wharton’s Criminal Law. § 1379; State v. Lewis, supra; Commonwealth v. Ashe, supra. See the cases cited in 70 A.L.R.2d 1449 § 11.
The fact that the evidence did not support the information :for burglary in the first degree but one for burglary in the second degree, does not affect the prisoner’s condition to the ■effect that when he escaped he was serving a sentence for ■felony, rendered by a competent court. The crime committed by him when he escaped is a fenoly notwithstanding the fact that subsequently the sentence he was serving was set aside and another rendered for a misdemeanor.
For the foregoing reasons the sentence rendered by the .Superior Court will be affirmed.
An information was filed against the plaintiff for the crime of Burglary in the First Degree. He was arraigned and a copy thereof was given to him. Counsel for his defense was appointed. He pleaded guilty and was sentenced. Said sentence was unappealable but it was reviewable by certiorari. Section 347 of the Code of Criminal Procedure — 34 L.P.R.A. $ 1074.
The difference in the severity of the sentence for the different modalities of the offense does not violate the equal protection of the laws. Pennsylvania ex rel. Sullivan v. Ashe, 302 U. S. 51, 88 L. Ed. 43.
Considering that our laws guarantee the basic rights of every accused' in a criminal prosecution and considering further the traditional attitude-of our courts towards the protection of those rights, it may be stated that, in all probability it will be at the stage of the arrest where in nearly all its totality the outstanding situations in which the escape will be justified will appear.