Running Local LLMs on a 24GB M4 Mac: What Actually Fits
How much of 24GB the GPU can use, which models fit at 4-bit (Qwen 3.5/3.6, Gemma 4, gpt-oss-20b), measured M4 speeds, and Ollama vs LM Studio vs MLX.

Apple’s M4 chip put unified memory into laptops and desktops that don’t require a server budget. For developers who want to run language models without an API bill, the 24GB MacBook Air or Mac mini is the cheapest serious entry point. The question isn’t whether local LLMs work on it — they do. The question is which models fit, how fast they run, and where the cliffs are.
Short answer: on a base 24GB M4, plan on about 18GB for model weights plus context. Dense models up to about 14B at 4-bit fit with room to spare. Mixture-of-experts (MoE) models up to about 20B total fit and run fast. 27B-32B models squeeze in only after you raise the GPU memory limit, and 35B MoE and 70B models don’t fit at all.
What fits in 24 GB
Sizes below are Ollama download sizes from each model’s library page, at the default 4-bit-class quantization. “Default budget” means the ~17-19 GB the GPU can use without changing any settings (explained in the next section).
| Size class | Example Ollama tags | Download size | Fits the default budget? | Notes |
|---|---|---|---|---|
| 7B-9B dense | qwen2.5-coder:7b, qwen3.5:9b | 4.7 GB; 6.6-7.6 GB | Yes | Lots of room for long context |
| 12B-14B dense | gemma4:12b, qwen2.5-coder:14b | 7.7-8.0 GB; 9.0 GB | Yes | The comfortable ceiling for dense models |
| 20B MoE (3.6B active) | gpt-oss:20b | 14 GB | Yes | ~3-5 GB left for context |
| 26B MoE (3.8B active) | gemma4:26b | 16-19 GB | Borderline | One report hit the GPU limit at Q4 and switched to a 12 GB Q3 build |
| 27B-32B dense | qwen3.6:27b, gemma4:31b, qwen2.5-coder:32b | 18-19 GB; 19-20 GB; 20 GB | Only after raising the limit | Short context, other apps closed, slow |
| 30B MoE (3.3B active) | qwen3-coder:30b | 19 GB | Only after raising the limit | Fast per token, but little room for context |
| 35B MoE | qwen3.6:35b, qwen3.5:35b | 22-23 GB | No | Needs a 32GB+ Mac |
| 70B dense | — | ~40 GB+ (math below) | No | Not close |
Sources for the sizes: Ollama library pages for qwen2.5-coder, qwen3.5, qwen3.6, gemma4, gpt-oss, and qwen3-coder. The Gemma 4 and Qwen 3.5/3.6 tags are multimodal (Ollama lists text and image input), so part of each download is the vision component. Parameter counts come from the model cards: gpt-oss-20b is “21B parameters with 3.6B active” (Hugging Face), Gemma 4 26B-A4B is 25.2B total with 3.8B active (Hugging Face), Qwen3-Coder 30B has “3.3B activated” (Ollama), Qwen3.6-35B-A3B has 3B activated (Hugging Face), and Qwen3.6-27B is dense (Hugging Face).
The memory math
Weights ≈ parameters × bits per weight ÷ 8. A “4-bit” Q4_K_M file works out to roughly 5 bits per weight once the higher-precision layers are included: qwen2.5-coder:32b is 32B parameters and a 20 GB download (32 × 5 ÷ 8 = 20). The same math puts a 70B model at about 70 × 5 ÷ 8 ≈ 44 GB, which is why 70B is out of reach on any 24GB Mac. gpt-oss uses MXFP4, where the MoE weights are “quantized to 4.25 bits per parameter” (Ollama), so its 21B parameters come to 14 GB.
Then add context. The KV cache grows with context length, and how fast it grows depends on the architecture. Add a few hundred MB of compute buffers on top. In one published llama.cpp load of Gemma 4 26B-A4B on a 24GB Mac, compute buffers took 523 MB and a q4_0-quantized KV cache at 16K context took 174 MB (Kartit). At the other end, llmcheck estimates that Qwen 3.6-35B-A3B with a 64K-token, 16-bit KV cache needs about 26 GB in total (llmcheck; their figure is an estimate from the model config, not a measurement). As a planning rule, leave 1-3 GB of the budget free for short-to-moderate context, and more for long coding-agent sessions.
MoE models fit by total size but run by active size. Every expert has to sit in memory, so the 21B-parameter gpt-oss-20b needs its full 14 GB. But each token only reads the active parameters (3.6B), which is why an MoE model generates far faster than a dense model of the same file size.
How much of the 24GB the GPU can use
Unified memory means your CPU and GPU share one pool. macOS does not let the GPU wire all of it. Metal reports the default cap as recommendedMaxWorkingSetSize, which llama.cpp prints at startup; Apple does not document the formula. On a 24GB machine that is about 17.2 GB on macOS 15 (two-thirds of RAM, the pattern public logs show on 32GB-and-smaller Macs) and about 19 GB on macOS 26 and later (17.76 GiB in reports from mlx-video and MoltenVK). Some machines report less: one 24GB M4 Pro run hit a Metal limit of about 16 GB (Kartit). Read your own value from that log line. As a rounded planning figure between those two defaults, plan on ~18GB for model weights plus KV cache.
You can raise the ceiling with the iogpu.wired_limit_mb sysctl, which takes megabytes:
sudo sysctl iogpu.wired_limit_mb=20480 # let the GPU wire up to 20 GB
sudo sysctl iogpu.wired_limit_mb=0 # back to the system default
- The name is confirmed by MLX’s docs. The
mlx.core.set_wired_limitpage says a wired limit above the system limit is an error, and givessudo sysctl iogpu.wired_limit_mb=<size_in_megabytes>as the way to raise the system limit (MLX docs). The same page says the MLX function is “only useful on macOS 15.0 or higher.” - It does not survive a reboot. It needs no reboot to take effect, it is not persistent by default, and
0restores the default (devnote). Making it permanent through/etc/sysctl.confmay require disabling SIP, per the same note. - Older macOS used a different key. On Ventura and earlier it was
debug.iogpu.wired_limit, in bytes (devnote). - On 24GB, every GB you give the GPU comes out of macOS. The devnote recommends leaving 8-16 GB for macOS and other processes, which a 24GB Mac can’t do once you raise the limit to fit a 20 GB model. Raising it to 20480 leaves about 4 GB for everything else, so expect swapping unless you close other apps.
How fast it runs: measured numbers, then estimates
Measured on a base M4 (both from llama.cpp’s Apple Silicon benchmark thread, run with llama-bench):
| Model | Hardware | Prompt processing (512 tok) | Generation |
|---|---|---|---|
| LLaMA 7B Q4_0 (3.56 GiB) | M4, 10-core GPU, 120 GB/s | 221 tok/s | 24.1 tok/s |
| qwen2.5-coder:7b Q4_K_M (4.36 GiB) | Mac mini M4, 24 GB, macOS 26.4 | 240 tok/s | 22.6 tok/s |
| llama3.2:3b Q4_K_M (1.87 GiB) | Mac mini M4, 24 GB, macOS 26.4 | 530 tok/s | 46.0 tok/s |
Those runs land at roughly 75-90% of the simple bandwidth ceiling (120 GB/s ÷ file size). That ceiling gives a usable estimate for sizes nobody has published base-M4 numbers for. The figures below are estimates, not measurements, and real speed will be lower:
- 12B-14B dense (8-9 GB): ceiling ~13-15 tok/s. Usable interactively, but you will watch it type.
- 27B-32B dense (18-20 GB): ceiling ~6 tok/s. Fine for a batch job, painful for chat.
- 20B-30B MoE (3.3B-3.8B active, about 2 GB read per token): ceiling roughly 50-70 tok/s. Real MoE throughput lands well below that ceiling: Kartit measured 49 tok/s for Gemma 4 26B-A4B at Q3 on an M4 Pro (Kartit), a chip with 2.3x the base M4’s bandwidth. We found no published base-M4 measurement for these MoE models.
Prompt processing (the time before the first token) scales with prompt length. At ~220-240 tok/s for a 7B model, a 4,000-token prompt means a wait of more than 15 seconds before output starts, and bigger models are slower. For agentic coding workflows that put a whole file into context, this matters more than steady-state tokens/sec.
Which model to start with
- For coding agents and tool use:
qwen3.5:9b. Johanna Larsson tried several models on a 24GB M4 MacBook Pro in LM Studio. Qwen 3.6 at Q3, GPT-OSS 20B, and Devstral Small 24B “technically fit in memory but were in practice unusable”, and Qwen 3.5-9B was the one she kept, with working tool use and a 128K context (jola.dev). She also found it much weaker than frontier models: it loops and misreads requests unless you guide it step by step. - For the most capability that fits:
gpt-oss:20b. At 14 GB it is the largest model in the table that fits the default budget with room for context, and its 3.6B active parameters keep it fast for its size. Larsson’s verdict above shows that “fits” is not the same as “works well for agents” — test it on your own task before committing. - For a 26B MoE: Gemma 4 26B-A4B at Q3, through llama.cpp. Kartit’s Q4_K_M attempt on a 24GB Mac exceeded the Metal GPU limit with a compute error. A 12 GB Q3_K_XL build, a q4_0 KV cache, flash attention, and
--no-mmproj(which skips the vision encoder) brought total GPU use to about 13 GB (Kartit). - For 27B-32B dense (
qwen3.6:27b,gemma4:31b,qwen2.5-coder:32b): only with the wired limit raised, other apps closed, and short context. At an estimated ~6 tok/s ceiling, most people will prefer a smaller model or a 32GB+ Mac. Our 30B and 70B memory guide covers the larger configurations.
For a deeper comparison of MoE options on this exact memory size, see picking an MoE model for a 24GB Mac with MLX. If you are deciding between 16GB and 24GB, the 16GB M4 guide covers the smaller budget.
Ollama vs LM Studio vs llama.cpp vs MLX
Four tools, overlapping audiences.
Ollama gives you a model registry, automatic downloads, and a REST API on localhost:11434. The CLI is one command: ollama run qwen3.5:9b pulls and starts the model. Its OpenAI-compatible endpoint at /v1/chat/completions means most existing client libraries work without changes. On Apple silicon, Ollama now has an MLX engine: the March 2026 preview asked for “a Mac with more than 32GB of unified memory” (Ollama), and a June 2026 post runs it through -mlx tags such as gemma4:12b-mlx without stating a memory minimum (Ollama). Ollama 0.30 also added GGUF support through llama.cpp, which “augments Ollama’s MLX engine on Apple silicon” (Ollama). One caveat from April 2026: Kartit reported that Ollama’s tool-call parser lost Gemma 4 tool calls and moved to llama.cpp (Kartit). That is a single report, so check the current release.
LM Studio is the GUI option. It runs llama.cpp (GGUF) models, and “on Apple Silicon Macs, LM Studio also supports running LLMs using Apple’s MLX” (LM Studio docs). It requires macOS 14.0 or newer and recommends 16GB+ of RAM (LM Studio).
llama.cpp is the engine under most GGUF tools. Use it directly when a model is a tight fit or you need flags the wrappers hide: quantized KV cache (-ctk q4_0 -ctv q4_0), flash attention (-fa on), skipping the vision projector (--no-mmproj), speculative decoding, and grammar-constrained output. Kartit’s Gemma 4 26B setup above is a working example of those flags on a 24GB Mac.
MLX is Apple’s own ML framework. The mlx-lm package runs models in MLX format (look for mlx-community/*-4bit repos on Hugging Face). On the same model and quantization, MLX is often faster than llama.cpp on Apple Silicon, though the gap varies by model and version. The downside is a smaller ecosystem than GGUF. If you only need one model for a specific app, MLX is worth benchmarking.
A note on Cursor: pointing Cursor’s OpenAI base URL at localhost:11434 does not work, because “Cursor’s servers try to call localhost on their own machines, not yours,” and Tab autocomplete always uses Cursor’s own model (ngrok). A tool that runs on your machine avoids both problems.
OpenCode
OpenCode is a terminal coding agent that runs on your machine. It probes Ollama at 127.0.0.1:11434 and discovers installed models, and it also supports LM Studio's local endpoint, so the agent can use a model running on your own Mac.
Affiliate link · We earn a commission at no cost to you.
When Local Beats Cloud
Local LLMs aren’t replacing frontier cloud models for every task. The honest tradeoff: the models that fit in 24GB lose to current frontier models on hard reasoning, long-context retrieval, and instruction following. Larsson’s experience with Qwen 3.5-9B is typical: useful as a research assistant and a rubber duck, unreliable when left to finish multi-step work alone (jola.dev).
Where local wins:
- Privacy-sensitive code review: you control where the prompt and source go, the same argument behind running a coding agent against a local model.
- Batch processing: a 5,000-document summarization job over a weekend costs you electricity, not API tokens.
- Offline development: airplanes, training rooms, anywhere the WiFi is unreliable.
- Tool-use prototyping: iterate on tool schemas without paying for each test run.
If your workflow is “ask a hard question once a day,” cloud models are still the right answer. If it’s “make 500 cheap calls a day to summarize, classify, or draft,” the math favors hardware you already own.
What this article did not test
- No model was run for this article. Model sizes are Ollama download sizes; the GPU budget comes from public
recommendedMaxWorkingSetSizereports. - Measured speeds are other people’s
llama-benchruns, cited above. Every other tokens/sec figure is a bandwidth-ceiling estimate, and real speed is lower. - We found no logged, minute-by-minute test of sustained LLM inference on the fanless M4 MacBook Air, so throttling is not quantified here.
- Power draw, battery life, and answer quality were not measured.
FAQ
Which models can I run in Ollama on a 24GB MacBook Air or Mac mini M4?
How many parameters can an M4 with 24GB of RAM run?
How do I increase the GPU memory limit on a Mac for MLX or llama.cpp?
Can I run a 32B model at Q4 on a 24GB Mac, and how much context do I get?
What is the best MoE model for a 24GB Mac?
Does the fanless MacBook Air M4 throttle during long LLM runs?
Will a 16GB M4 Mac work for local LLMs?
Is MLX worth switching to from Ollama?
How much battery does running a local LLM drain?
Tools used in this review
Some links above are affiliate links. We may earn a commission if you sign up. See our disclosure for details.
Related reading
2026-09-02
DeepSeek MLA: 70 GB of KV Cache at 1M Tokens
No DeepSeek-V4 config is public yet. The V3 one is, and its KV-cache math tells you what a million-token window actually costs in GPU memory.
2026-08-13
AI Agent Auth: API Keys vs Device Flow vs Scoped Tokens
Three credential models for non-human callers: static keys, the OAuth 2.0 device grant, and short-lived scoped tokens - and when each one fits.
2026-08-12
Writing a Spec an AI Agent Can Actually Execute
Ground truth files, an interface contract, one acceptance command, and explicit out-of-bounds rules -- so the agent runs end to end without babysitting.
2026-07-16
Multi-Agent Terminal Workflows with OpenCode and Aider
How we split work across OpenCode, Claude Code, and Aider in one terminal without losing track of which agent changed what.
2026-07-16
OpenCode First Project Setup: Install to First Passing Test
Configure providers, context files, and project conventions so the agent produces useful output on an existing codebase from day one.
Get the best tools, weekly
One email every Friday. No spam, unsubscribe anytime.