A homophonic pun is a play on words that sound the same but have different meanings, while a homographic pun is a play on words that are spelled the same but have different meanings.

Example of homophonic pun:

Why was the math book sad? Because it had too many problems.

Example of homographic pun:

I used to play piano by ear, but now I use my hands.