How to Measure and Reduce Time to First Byte (TTFB): 5 Steps to Fix a Slow Server Response

A page "feels slow" and someone opens DevTools. The first byte arrives at 874 ms, so the verdict is "the server is slow" and the team starts tuning SQL. But the same request printed this:

dns 0.012 connect 0.045 tls 0.112 ttfb 0.874 total 0.921

Those numbers are cumulative seconds from the start of the request. Subtract neighbours and the server did 762 ms of work — but DNS, TCP and TLS together were only 112 ms. If you are chasing high TTFB or a slow server response time, this is the first thing to check: TTFB is not one number with one owner; it is five waits with five owners, and only one of them is the server.

Step 1 — Measure the full TTFB

To measure time to first byte from the server side, use PHP's cURL, which exposes every phase through curl_getinfo():

<?php $ch = curl_init('https://example.com/'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_NOBODY => true, CURLOPT_TIMEOUT => 10, ]); curl_exec($ch); $i = curl_getinfo($ch); printf("dns %d ms\n", $i['namelookup_time'] * 1000); printf("tcp %d ms\n", ($i['connect_time'] - $i['namelookup_time']) * 1000); printf("tls %d ms\n", ($i['appconnect_time'] - $i['connect_time']) * 1000); printf("ttfb %d ms\n", $i['starttransfer_time'] * 1000); printf("total %d ms\n", $i['total_time'] * 1000);

Step 2 — Split it into five phases

Each curl_getinfo field is a timestamp, not a duration. Subtract the previous one to see where the TTFB delay actually is:

  • DNS — namelookup_time. A cold resolver costs 20–35 ms; a cache hit is ~1 ms.
  • TCP connect — connect_time − namelookup_time. One round trip; this is your distance to the server.
  • TLS handshake — appconnect_time − connect_time. Extra round trips and certificate chain size live here.
  • Server wait — starttransfer_time − appconnect_time. Application, database, cache miss. The only part your code controls.
  • Download — total_time − starttransfer_time. Body size and compression.

Step 3 — Read the thresholds correctly

Three "Google numbers" get quoted interchangeably when people try to reduce TTFB. They are not the same measurement:

  • 800 ms — web.dev TTFB guidance, 75th percentile of real visits. Above 1.8 s is poor.
  • 600 ms — Lighthouse server-response audit, which excludes DNS and redirects.
  • 200 ms — deprecated PageSpeed v4 guidance. Historical only; a useful stretch goal, not a pass/fail line.

Step 4 — Match the slow phase to the fix

This is the part most guides skip: how to fix high TTFB depends on which phase is large.

  • DNS > 100 ms — slow resolver, or TTLs so short nothing caches. Raise TTLs; the second run should drop to near zero.
  • TCP high — distance. A CDN or a closer region, not application tuning.
  • TLS high — missing session resumption, oversized chain. Enable keep-alive and OCSP stapling.
  • Server wait high — cache the HTML, then fix the slowest query. This is the only phase where code changes help.
  • Download high — compress with Brotli/gzip and shrink the body.

Step 5 — Verify from where your users are

A single sample from one region is a smoke test, not a verdict. Run the check from your users' region, compare percentiles rather than one average, and re-run after each fix. The batch Domain Comprehensive Query tool returns status, redirect chain, TLS, response time and TDK with a 0–100 score for up to 10 URLs, so you can spot the slow rows first. Confirm a single slow row with the HTTP Status Checker, which shows the full redirect chain and per-stage timing. If the wait is DNS, the DNS Lookup tool lists A, AAAA, MX, TXT and NS records. When the first byte is fine but the snippet is weak, the Meta Tag Extractor shows what the crawler sees. And for the full picture beyond one URL, the AI Website Audit goes deeper.

Stop calling TTFB "the server". It is five waits, and the fix belongs to whichever one is actually large — the unique angle is that the only number you can reach by tuning code is the smallest of the five, and the other four are decided before your application ever runs.

View all developer tools →

Author's note: All tool links are self-hosted, pure client-side, no account, no ads, no tracking.