Short answer. When both parents are gone, all grandparents who are equally close in degree inherit together rather than one side excluding the other. If grandparents from both the father's and mother's lines survive, one-half of the inheritance goes to the paternal line and one-half to the maternal line, divided equally within each line.
What the law says
In default of the father and mother, the ascendants nearest in degree shall inherit. Should there be more than one of equal degree belonging to the same line they shall divide the inheritance per capita; should they be of different lines but of equal degree, one-half shall go to the paternal and the other half to the maternal ascendants. In each line the division shall be made per capita.
Civil Code, Article 987 — Nearer Ascendants Exclude the Rest. Read the full provision →
The nearest-degree ascendant inherits
Article 987 starts from a simple rule: once both father and mother are gone, it is the ascendants nearest in degree who inherit. Grandparents are two degrees removed from the deceased, so if they survive, they take ahead of great-grandparents or any more distant ascendant, regardless of which side of the family they come from. A more distant ascendant only comes into the picture once no one at the nearer degree is left alive.
Grandparents on both sides share, split by line
Where grandparents from both the paternal and maternal sides are alive, the law does not let one side take everything. Article 987 splits the inheritance in half: one-half goes to the paternal ascendants, and the other half goes to the maternal ascendants. Neither line excludes the other — both grandfather-and-grandmother pairs share, just from their own half of the estate.
How the split works within each line
Within each line, the division is made per capita — meaning it is divided equally, head by head, among however many ascendants of that line are alive at that degree. If both the paternal grandfather and grandmother survive, they split the paternal half between the two of them equally; the same applies on the maternal side with its own half, regardless of how the two halves compare against each other.
What happens with only one line surviving
The half-and-half split in Article 987 only comes into play when ascendants of different lines but equal degree are competing. If grandparents on only one side are alive — say the maternal grandparents survived but both paternal grandparents are gone — the surviving line's ascendants divide the entire inheritance per capita among themselves, since there is no other line at the same degree left to share it with. The article does not address what happens if grandparents on neither side survive — that situation is governed by the rules for more distant ascendants, not by Article 987 itself.