How to compress a video to a target file size (and why the math matters)
How bitrate, duration and file size relate, how to work out the bitrate for a limit like 25 MB, and why re-encoding can't improve a video.
Email attachments, chat apps, upload forms and Discord-style services all have file size limits, and phone videos regularly blow through them: a minute of 4K footage can easily be several hundred megabytes. Compressing to a specific size is not guesswork. There is a direct relationship between size, length and bitrate, and once you know it you can predict the result before you start encoding.
The one formula you need
A video file is mostly the video stream plus the audio stream. Each stream has a bitrate, the amount of data per second of playback, usually given in kilobits per second (kbps). So:
file size ≈ (video bitrate + audio bitrate) × duration
Turn it around and you get the bitrate needed for a target size:
total bitrate = target size ÷ duration
Units are where people slip. File sizes are in bytes and bitrates in bits, and there are 8 bits in a byte. A megabyte here means 1024 × 1024 bytes, which is 8,388,608 bits, or 8192 kilobits if you count a kilobit as 1024 bits.
A worked example: 25 MB for a one-minute clip
Say you need a 60-second clip under 25 MB.
- Keep a safety margin, because encoders do not hit a bitrate exactly and the container adds a little overhead. Aim for about 94% of the limit: 25 × 0.94 = 23.5 MB.
- Convert to kilobits: 23.5 × 8192 ≈ 192,500 kilobits.
- Divide by duration: 192,500 ÷ 60 ≈ 3,200 kbps total.
- Reserve the audio. AAC at 128 kbps is good for speech and most music, which leaves about 3,080 kbps for video.
Is 3,000 kbps enough? For 1080p it is usable for calm footage but will show blocking in fast motion. For 720p it is comfortable. This is the real trade-off behind every size limit: a longer video or a smaller limit means fewer bits per second, and the best way to spend fewer bits is often to lower the resolution so the remaining bits are shared among fewer pixels.
Rough bitrates by resolution
As a starting point for H.264 at 30 frames per second, these are bitrates where most content looks good:
- 480p: about 1,400 kbps
- 720p: about 2,800 kbps
- 1080p: about 5,000 kbps
- 1440p: about 8,000 kbps
- 4K (2160p): about 16,000 kbps
If the bitrate your size limit allows is well below the figure for your resolution, scale the video down a step. A clean 720p video looks better than a blocky 1080p one.
Other ways to make room
- Trim it. Duration is in the formula directly. Cutting a 60-second clip to 30 seconds doubles the bitrate you can afford. Use a video trimmer before compressing.
- Lower the frame rate. Going from 60 to 30 fps cuts the amount of motion to encode. The saving is less than half, because consecutive frames share most of their content, but it is noticeable for screen recordings and gameplay.
- Drop or shrink the audio. If the clip doesn't need sound, removing the audio frees the 128 kbps for video. For speech only, 64 kbps is usually fine.
Why compression can't improve a video
A common surprise: you "compress" a video and the file gets bigger. That happens when the target bitrate is higher than the source's own bitrate. Re-encoding cannot add detail that is not in the source. Spending more bits only reproduces the existing compression artefacts more precisely, and every lossy re-encode loses a little more quality on top.
So a sensible compressor caps its bitrate at the source's bitrate. You can find the source's bitrate by dividing its size by its duration, or check it directly with a video info tool. If a file is already below your size limit, the best thing to do is usually nothing.
Why the result is rarely exactly the target
Encoders treat the bitrate as an average to aim for, not a hard rule. Simple scenes use fewer bits than the average and complex scenes more, and a short clip doesn't give the encoder much time to balance out. That is why the safety margin exists. Expect the output to land a few percent below the target. If it comes out above, the clip probably had a lot of motion or noise, and a second pass with a slightly lower target will fix it.
Doing it in the browser
Modern browsers have a built-in hardware-accelerated video encoder, exposed to web pages as the WebCodecs API, in recent Chrome, Edge and Safari. The Video Compressor on this site uses it to apply exactly the calculation above. Enter a target size and it works out the bitrate, caps it at the source's bitrate, and encodes on your own device. The video is never uploaded, which matters for private recordings and avoids upload time on large files.