You might be thinking of the Heine-Borel theorem, which says that every compact subset of the real line is a closed and bounded subset of the real line.
But "closed" and "open" do not quite behave like you might think.
For example, consider the topological space $X = [0,1] \cup [2,3]$, equipped with the subspace topology relative to the whole real line.
In this space $X$, its subspace $[0,1]$ is compact (because the subspace topology of $[0,1]$ relative to $X$ is identical to the subspace topology of $[0,1]$ relative to the real line).
On the other hand, $[0,1]$ is an open subset of $X$ (because it is the intersection of $X$ with $(-1/2,3/2)$ which is an open subset of the real line). As it turns out, $[0,1]$ is also a closed subset of $X$. So, it is both closed and open in $X$ (but it is not open in the real line, of course).