From: http://www.chabad.org/library/article_cdo/aid/932325/jewish/Chapter-One.htm
Halacha 13
[The following principles apply when] a child is born in the eighth month [of pregnancy]:1 If the child's nails and hair are completely formed, we assume that this is a completely formed infant that should have been born in the seventh month, but whose birth was delayed. Hence, the baby may be carried on the Sabbath, is not considered to be a stone, and may be circumcised on the Sabbath.
If, however, when the baby was born, its hair and nails were incompletely formed, we can be certain that this child is in its eighth month of development and should not have been born until the ninth month, but was born prematurely. Therefore, he is considered as a stone and may not be moved on the Sabbath.
Nevertheless, if such an infant remains alive for thirty days, he is considered to be a child who will live and is governed by all the same rules as other infants.2 Whenever a human child lives longer than thirty days, it is no longer considered to be a stillborn.
Halacha 14
[The following rules apply when] a child is born in the seventh month of gestation: If a child is born with his limbs completely formed,3 we assume that he will live and he should be circumcised on the eighth day [even if it falls on the Sabbath].
If there is a question whether a child4 was born in the seventh month or in the eighth month, he can be circumcised on the Sabbath. The rationale is: If he was born in the seventh month and his limbs are completely formed, it is appropriate that [his circumcision] supersede [the prohibitions against labor on] the Sabbath. If he was born in the eighth month, circumcising him [does not constitute a violation of the Sabbath prohibitions].5 It is like cutting meat, because he is like a stillborn if he is, in fact, born in the eighth month.
Footnotes 1 (rest don't discuss this topic):
The comprehension of this and the following halachah are dependent on the following two Talmudic passages:
[The prohibitions against labor on] the Sabbath are superseded for [the circumcision of a child] born in the seventh month, but not for a child born in the eighth month (Shabbat 135a).
A child born in the eighth month is like a stone and may not be carried [on the Sabbath]. His mother may, however, lean over him and nurse him....
Rabbi states: [This is when] his physical features reflect his [lack of development]; i.e., when his hair and nails are not completely formed.
[Rabbi's statements imply that] if [his hair and nails] are completely formed, he is a baby that should have been born in the seventh month, but whose birth was delayed (Yevamot 80b).
From these passages, it appears that the Sages considered that there were two periods of gestation that could produce healthy babies, a seven-month period and a nine-month period. Therefore, a baby who was born in the seventh month was considered to be healthy, and circumcision could be performed on the Sabbath.
In contrast, a baby born in the eighth month was generally considered to be unhealthy. Not only was the baby not to be circumcised on the Sabbath, but moving it at all was forbidden. Since it was likely to die, it was considered to be muktzeh. If, however, a baby born in the eighth month looks healthy, we assume that it should have been born in the seventh month, but its birth was delayed. Therefore, it is considered a healthy baby and it may be circumcised on the Sabbath.
We have used the past tense in the above explanation, because these laws are no longer practiced, and all babies are allowed to be moved on the Sabbath. Tosafot, Shabbat, loc. cit., state that at present, it is no longer possible to determine exactly when a child was conceived, and we therefore do not know the month of pregnancy the mother was in. Furthermore, the advances in medical technology have enabled the lives of many premature babies to be saved despite the fact that, without these new developments, these babies would surely not have survived. At present, it is considered a mitzvah to try to save the lives of any premature babies, even if doing so involves carrying out forbidden labors on the Sabbath.
Also, it must be emphasized that, as stated in Halachot 16-18, a child is circumcised only when it is healthy and there is no danger involved. This is surely relevant with regard to premature infants. Rarely, if ever, would a doctor grant permission for such a baby to be circumcised on the eighth day of his life.
(I hope I didn't overdo it with copying the text.)