Let

. Since both

and

are subgroups of

, we have

Because both

are subgroups of

, then

contains the identity element

. Furthermore, there must be some element

and

, i.e.

, such that

.
Now let

. By the same reasoning as above it follows that each of these belong in

, and since

is a group, we have

, so

is associative under

.
So

contains the identity, is closed with respect to inverses, and is associative under

. Therefore

must be a subgroup of

.
In the case of union, this is not always the case. Consider the group

with subgroups

and

where

is the set of all integer multiples of 2 and

is the set of all integer multiples of 3.
It's easy to show that

and

are indeed subgroups, but this is not the case for

. We have

Take the elements

and

. Addition yields

, but

, so

is not closed under

.