Dev.to
7/15/2026

How to Detect a Website Visitor's Country from Their IP Address: 3 Methods Compared
Short summary
Three methods for detecting a visitor's country from IP: CDN headers (free, country-only), self-hosted databases like MaxMind GeoLite (offline, high volume, maintenance burden), and geolocation APIs like ipstack (zero maintenance, per-lookup cost). The article provides clear decision rules: use CDN headers for country-only needs, APIs for small teams needing city-level data, and self-hosting for massive volume with dedicated ops.
- •CDN headers (e.g., CF-IPCountry) are free and instant for country-only detection
- •Self-hosted databases like GeoLite2 offer offline lookups but require update pipeline ownership
- •Geolocation APIs trade per-lookup cost for zero maintenance and richer data
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



