We can make a compound sentence by joining two simple sentences with comma, and. Here are two simple sentences:
I play volleyball. Anna plays basketball.
Join these two simple sentences with a comma, and. I play volleyball, and Anna plays basketball. Now we have a compound sentence.
We need comma, and because two complete thoughts are being joined. Each complete thought has a separate subject who is doing something. I am playing. Anna is playing. We separate the two complete thoughts with comma, and.
But not every and needs a comma.
Look at this sentence. I like taking walks and riding my bike.
Do not put a comma in this sentence. Only one person is doing something. There is no subject after and who is doing something, so there is only one complete thought. This is a simple sentence.
Only use comma, and when there are two complete thoughts. Do not put a comma after and unless there is a subject doing something after the and.
A. The team was running laps and doing pushups.
B. I like cookies and Dad likes ice cream.
C. I peel carrots and Mom cuts them up.
D. The doctor visited the hospital and gave a lecture.
Did you pick B and C? Both B and C have two complete thoughts. Somebody is doing something after the and. Sentences B and C are compound sentences. They need comma, and.