Expresses doing a secondary action while taking advantage of the occasion of a main action — 'while I'm at it' or 'on the same occasion'. The main action is the primary purpose; the ついでに action is an add-on that conveniently fits in.
[Verb plain form] / [Noun] + の + ついでに
買い物のついでに、郵便局に寄った。
Kaimono no tsuide ni, yuubinkyoku ni yotta.
While out shopping, I dropped by the post office.
Noun 買い物 + の + ついでに makes the post office stop an add-on to shopping.
散歩するついでに、パンを買ってきて。
Sanpo suru tsuide ni, pan wo katte kite.
While you're out for a walk, buy some bread.
Verb plain form 散歩する + ついでに tacks buying bread onto the walk.
出張のついでに、実家に顔を出した。
Shucchou no tsuide ni, jikka ni kao wo dashita.
While on the business trip, I stopped by my parents' home.
Noun 出張 + の + ついでに frames the visit as convenient to the main trip.
• The main action is the real purpose; the ついでに action just fits in conveniently. • With nouns, insert の (買い物のついでに). • Register: neutral; extremely common in daily speech.
The JLPT rarely asks whether you recognise a pattern — it asks which of several similar patterns fits. These are the ones ついでに is tested against.
がてら is more formal/literary and treats both actions as roughly equal, while ついでに clearly makes the second action a convenient extra.
際に simply means 'on the occasion of' with no 'extra convenient task' nuance; ついでに specifically adds a piggybacked action.
Study Japanese grammar on LenGaki

Get the Android app
The app adds offline study, home-screen widgets, stroke-order tracing, speaking practice with pronunciation scoring, and an AI tutor that answers questions in context — none of which fits in a browser tab.