MP4 and MKV are both container formats — they don't define how video is compressed, they define how video, audio, and metadata are packaged together. The same H.264 or H.265 video can exist inside either container. The difference is what else the container can carry and where it can play.
MP4 (MPEG-4 Part 14) is the universal standard. It plays natively on every phone, tablet, computer, browser, smart TV, and media player. Social media platforms, streaming services, and video editors all expect MP4. If you need a video that "just works" everywhere, MP4 is the answer.
MKV (Matroska) is the power user's format. It supports virtually unlimited audio tracks, subtitle tracks (including styled ASS/SSA subtitles), chapter markers, attachments (like fonts), and metadata. It's the preferred format for archiving movies and TV shows because it can carry the full complexity of a disc release — multiple languages, director's commentary, forced subtitles — in a single file.
The tradeoff is compatibility. MKV doesn't play natively on iPhones, in most web browsers, or on many smart TVs. You'll need VLC (free, plays everything) or another media player that handles MKV. If you're distributing video to a general audience, convert to MP4. If you're archiving for yourself and want to preserve every track and subtitle, keep it in MKV.