Docker Multi-stage Build Savings Calculator
Compare final image size before and after adopting multi-stage Docker builds.
Inputs
Final image size if everything (build tools + runtime) ships in one stage.
Size of compilers, SDKs and dev dependencies only needed to build the app.
Size of dependencies the app actually needs at runtime (e.g. shared libs, node_modules --production).
Size of the minimal runtime base image used in the final stage (e.g. alpine, distroless).
Image Size Savings
800MB
Savings vs Single-Stage
84.2%
Multi-Stage Final Image Size
150MB
Builder Weight Discarded
480MB
Step by step
Multi-stage final size: base + runtime deps
60 + 90
= 150MB
Savings: single-stage − multi-stage final
950 − 150
= 800MB
Savings %: savings / single-stage × 100
800 / 950 × 100
= 84.2%
Builder-only weight discarded
480MB never enters final image
= 480MB
How it works
A single-stage Dockerfile ships the base image plus every dependency used at any point in the build, including compilers and dev tooling never needed at runtime. A multi-stage build compiles in a throwaway 'builder' stage and copies only the finished artifacts into a minimal final stage. Formula: savings = single_stage_size − (base_runtime_image + runtime_deps); savings% = savings / single_stage_size × 100. The builder-only dependency weight is exactly what gets discarded.
Formulas
Multi-stage final image size
final_size = base_runtime_image + runtime_deps
- base_runtime_image
- Size of the minimal runtime base image (MB)
- runtime_deps
- Size of runtime-only dependencies (MB)
Image size savings
savings_percent = (single_stage_size - final_size) / single_stage_size × 100
- single_stage_size
- Single-stage image size (MB)
- final_size
- Multi-stage final image size (MB)
Frequently Asked Questions
What typically counts as a 'builder-only' dependency?
Compilers (gcc, tsc), SDKs, build caches, dev/test dependencies, and source files not needed at runtime — anything that exists solely to produce the final binary or bundle.
Can I have more than two stages?
Yes — Dockerfiles support any number of named stages (FROM ... AS name), and you can copy artifacts from any earlier stage with COPY --from=name. Two stages (builder + runtime) is the most common pattern.
Does multi-stage affect build time as well as image size?
Build time is largely unchanged (you still run the same build steps) but layer caching per-stage can speed up incremental builds; the primary win is the smaller shipped artifact, faster pulls, and reduced attack surface.
Why is a smaller final image good beyond disk space?
Smaller images pull faster (faster deploys and autoscaling), have a smaller attack surface for vulnerability scanners to flag, and reduce registry storage/egress costs at scale.
You might also need
- Docker Build Time EstimatorCommonly used together
- Docker Image Size CalculatorCommonly used together
- Docker Cache Efficiency CalculatorCommonly used together
- Docker Container Memory CalculatorCommonly used together
- Docker Layer Size CalculatorCommonly used together
- Docker Image Compression CalculatorAlso in Docker