Carbon is in Group 4 of the periodic table, so a carbon atom has four electrons in its outer shell. To fill the outer shell it needs four more electrons, and it gets them by sharing. A covalent bond is a shared pair of electrons between two atoms, and it forms between non-metal atoms.
Because carbon needs four more electrons, a carbon atom can form four covalent bonds. In methane, one carbon atom shares a pair of electrons with each of four hydrogen atoms, making four single bonds.
A double bond is a shared pair of electrons twice over, so it counts as two bonds. In carbon dioxide each carbon atom forms two double bonds. That is still four bonds in total, so carbon always makes four bonds, whatever the pattern.