Guides
Last updated
August 1, 2023

IP Geolocation Database: What it is & How it Works

Elizabeth (Lizzie) Shipton

Table of Contents:

Get your free
IP Geolocation
API key now
4.8 from 1,863 votes
See why the best developers build on Abstract
START FOR FREE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required

What is an IPĀ GeolocationĀ Database?

An IP geolocation database lets you look up where a user is by their IP address. The databases contain the latitude and longitude of each known IP address, so while you won't get an exact location (you can't get a street address, for example) you will get a fairly accurate understanding of where a user is accessing your site from.

Most geolocation services rely on these databases under the hood to do IP geolocation lookups. You can get information about a user's latitude and longitude, city, state, country, region, timezone, currency, and other location-based data.

Knowing this information is crucial to serving users a good experience on your site. Not only does it allow you to provide language translations and currency conversions, it also lets you serve tailored ads and can even assist with cyber security.

In this article, we'll talk about the basics of IP addresses and geolocation, the importance of geolocation databases, and how to determine which geolocation database service is right for your needs.

Key Takeaways:

  • An IP geolocation database allows you to look up a user's physical location based on their IP address.
  • Geolocation data can be used to improve user experience, prevent fraud, and restrict content based on geographic location.
  • Accuracy, frequency of updates, data coverage, customization options, and pricing are important factors to consider when choosing an IP database.
  • Responsible use of geolocation data is crucial to comply with data privacy regulations and ensure data security for users.
Letā€™s send your first free
IP Geolocation
call
See why the best developers build on Abstract
Get your free api

Understanding the Basics of IP Address

Before we dive into IP geolocation, let's briefly talk about what an IP address is.

Definition of IP Address

An IP address is a string of numbers that identifies a device to the internet. Every device that is connected to the web has a separate and unique IP that is used to send and receive network requests. Think of an IP address as a computerā€™s home address. While an IP address canā€™t reveal any personal information like your age, sex, or exact location, it can be used to look up geographic information.

An IP address changes based on where the computer is accessing the network from. Your computer's IP address at the local coffee shop will be different from its IP address at home.

There are two main formats for IP addresses: IPv6 and IPv4. IPv4 addresses are the ones that most people are familiar with. They look like this:

12.345.678.90

Each segment of the address is an 8-bit field. Each 8-bit field represents a byte of the address. There are 4 8-bit fields, so it is a 32-bit address. This format is often referred to as the 'dotted decimal' format.

IPv6 addresses look like this:



2001:db8:3333:4444:5555:6666:7777:8888

Each segment of an IPv6 address is any hexadecimal value between 0 and FFFF. IPv6 is a 128-bit address. This means that IPv6 offers 1,028 times more addresses than IPv4, which means we will not run out of available IPv6 addresses as more devices come online in the future.

Types of IP Addresses

In addition to the different formats of IP addresses, there are a few different types of IP addresses for every device, depending on where the device is, and where it is being accessed from.

A device has a private address that identifies it to the local network (for example, the network that runs off the router in your home.) It also has a public address, which is actually the IP address of your router, provided by your Internet Service Provider. It also has a local address (127.0.0.1 or localhost), and several others.

How IP Addresses are Assigned

IP addresses are mathematically produced and allocated by the Internet Assigned Numbers Authority (IANA.) They can be assigned to a device statically or dynamically. A static IP address will be assigned only once, and will be the same IP address that the machine uses to access the internet every time it logs on.

A dynamically assigned IP will change each time the device connects to the internet. A new address is generated at the start of every session.

What is IP Geolocation and How Does it Work?

IP geolocation is used to identify visitor's geographical location via their IP. Geolocation just means using data available through devices (such as GPS or IP) to figure out geographical location in the real world.

Techniques Used for IP Geolocation

The typical way in which geolocation data is gathered is by examining the IP address of an incoming request, then sending that IP address to an API or other online service that will use an IP database to look up the IP address and return the user's location.

Limitations of IP Geolocation

IP geolocation database instances are maintained by third parties, and the accuracy of the data within them depends largely on the methods used to collect the data, and the reliability of the party doing the data collection.

Many IP companies acquire their data through data mining, while others get more accurate data through user polls. Depending on the database you choose, the data you get could be collected via either method.

Additionally, as previously mentioned, IP geolocation data is not 100% accurate. You won't get personal information, or even be able to identify visitors' geographical location data down to a street address. You won't get a phone number or an idd country code. Most services return a radius within which the device is likely to be.

Benefits of Using an IP Database

Now that we know what an IP address is and how it can help us look up users' locations, let's talk about how a location database can help improve our website visitors' experiences.

Targeted Advertising

One of the most popular use cases for gathering IP geolocation data about your users is so that you can serve them highly targeted ads. Knowing a user's area code, for example, can be used to point them toward a brick-and-mortar store close to them.

You can also serve ads in the right language, show prices in the right currencies, and only show users ads that are relevant to them. Users who live in the country, for example, are unlikely to buy the same things as users who live in cities.

Fraud Prevention

By far the most important use of IP geolocation data is to prevent online fraud. Many online banks, credit card companies, and other financial institutions use user locations to determine whether a login request is fraudulent.

If a login attempt is made from an unexpected location - another country or even just another city, the website can prevent the login and alert the user that the account may have been comprised.

Another use of IP geolocation database data in preventing online fraud is to protect sites from DDOS (Distributed Denial of Service) attacks. Requests can be blocked from countries that are known to spawn a lot of these types of attacks, thus thwarting many attempts and keeping sites safe.

Improved User Experience

Knowing your user's IP address and physical location can also help you to improve their online experience on your site. You can show them language translations and currency conversions, as well as content that is most relevant to them.

Localizing content in this way makes it easier for users to browse your site and makes it more likely that they will make a purchase or become returning visitors.

Geographic Content Restriction

Finally, geographical location data can be used to restrict content in certain countries or regions. Many streaming services such as Netflix use this method to prevent content from being accessed in countries in which it is not licensed to play.

Types of IP Databases

When it comes to utilizing IP database information, there are a couple of different types, and the quality of the data in them may be different depending on the type. Additionally, connection speed, regulatory compliance, and other factors may change based on the type of database you use.

Commercial Databases

A commercial IP database is run for profit by a third-party company that specializes in providing geographical location data to its customers. They typically have increased accuracy over the free IP database options available, and their data collection methods are usually sound and comply with government regulations.

Here are a few of the most popular commercial IP database options:

  • IP2Location - provides IP-based geolocation data as well as other types of data including weather station code information, zip code to metro data, information on proxy servers, and more
  • Maxmind - database specializing in online fraud prevention
  • IPIP - downloadable database based on analysis of real-time BGP/ASN data

Free IP Databases

Free online databases can be less accurate than commercial ones but are usually good enough for small businesses, freelancers, and hobbyists. Some of the most popular free options include:

How to Choose the Right IP Database

Once you've decided that using Ip address data to determine your users' physical location is important, you'll need to evaluate some database options to decide which one is right for you. We recommend using the following criteria to make your decision.

Accuracy

As mentioned, the accuracy of geolocation data, in general, is not pinpoint perfect. You will only be able to narrow it down to a city and radius within some longitude and latitude points. That being said, some servers will provide more accurate data than others.

Frequency of Updates

Make sure that the data in the database is updated regularly. Stale data is as useless as no data - in fact, it can be worse than having no data, because you might serve your users incorrect content based on an inaccurate location.

Data Coverage

How many locations does the database provide data for? There may be gaps in the coverage map. This could be fine if you know that you don't have users in certain locations, but you should check where those gaps in the data are before you decide to use a service.

Customization Options

Before choosing a service, do a thorough audit of your specific needs to determine what you need the database to handle. How much flexibility does the service have? Can you do an IP address database download if need be?

Pricing

Finally, consider the cost of the service. We leave this until last because it's worth paying for features that you need, rather than limiting yourself by cost upfront. If a service is a little more expensive but provides more accurate data and better features, it's worth paying for it.

How to Implement an IP Database

The simplest way to implement an IP database is through an API. There are many geolocation APIs out there that connect to reliable, well-managed IP databases and make the process of gathering geographical location data about your users very easy.

Let's take a look at how to use the AbstractAPI Free Geolocation API to look up a user location based on an IP address.

Get an API Key

In order to use the API, you'll need to sign up for a free account and obtain an API key. The APi key authenticates you to the API and allows you to make requests. Your account is always free, and there are no ads or mailing lists to join. You can make up to 20,000 requests at 1 request per second.

Go to the API homepage and click "Get Started."

You'll need to input your email address and create a password. Then you'll be taken to the dashboard, where you'll see a testing sandbox and your API key.

Make a Request to the API

Check out the testing sandbox on the dashboard. You'll see code snippets for the most popular programming languages, including JavaScript, Python, Ruby, Java, PHP, and Go.

For the purposes of this tutorial, we'll work with JavaScript. AbstractAPI provides this snippet for JavaScript:



function httpGetAsync(url, callback) {
const xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
callback(xmlHttp.responseText);
}
}
xmlHttp.open("GET", url, true); // true for asynchronous
xmlHttp.send(null);
}

const url = "https://ipgeolocation.abstractapi.com/v1/?api_key=YOUR_API_KEY"

This code sends a GET request to the API endpoint, with your API key included as a query parameter in the URL. That's all you need to get geolocation information from the API.

You can also include an IP address as a query parameter in the URL. If no IP address is provided, the API will automatically pull the IP address of the machine that sent the request.

Once the API receives the request, it uses an IP database to look up the location information for that address and returns the data to you as a JSON (Javascript Object Notation) object. This is the format it returns for every language.



{
"ip_address": "XX.15.191.XXX",
"city": "XXX",
"city_geoname_id": XXXXXXX,
"region": "California",
"region_iso_code": "CA",
"region_geoname_id": XXXXXXX,
"postal_code": "XXXXX",
"country": "United States",
"country_code": "US",
"country_geoname_id": 6252001,
"country_is_eu": false,
"continent": "North America",
"continent_code": "NA",
"continent_geoname_id": 6255149,
"longitude": -121.9903,
"latitude": 36.9689,
"security": {
"is_vpn": false
},
"timezone": {
"name": "America/Los_Angeles",
"abbreviation": "PDT",
"gmt_offset": -7,
"current_time": "08:35:02",
"is_dst": true
},
"flag": {
"emoji": "šŸ‡ŗšŸ‡ø",
"unicode": "U+1F1FA U+1F1F8",
"png": "https://static.abstractapi.com/country-flags/US_flag.png",
"svg": "https://static.abstractapi.com/country-flags/US_flag.svg"
},
"currency": {
"currency_name": "USD",
"currency_code": "USD"
},
"connection": {
"autonomous_system_number": 7922,
"autonomous_system_organization": "XXXXX-XXX",
"connection_type": "Cable/DSL",
"isp_name": "XXX",
"organization_name": "XXXX"
}
}

Please note that some identifying information has been redacted from this output.

The API returns an object with detailed information about the user's city, state, region, country code, and area code, as well as other information like their ISP, timezone, currency, and even a country flag emoji.

You can now pull the relevant fields off the object and use them in your code. For example, grab the latitude and longitude values and use them to render a location for your user on a map.

Best Practices for Using IP Geolocation Database

When using sensitive information like user location on your sites, you must make sure you are complying with data privacy regulations and that you are ensuring data security for your users.

Additionally, you should never use a user's location to engage in discriminatory practices against that user.

Finally, monitor the IP datasets you return and the performance of the database to make sure that slow requests or stale data aren't impacting your users' experiences on your site.

Limitations and Challenges of Geolocation Data

There are many challenges to using geolocation data. Most commonly, the issue site owners come up against is the use of VPNs and proxy servers by users to maintain their privacy and circumvent IP lookups.

A VPN or proxy will mask the user's real IP address, allowing them to download content in regions they should not be able to access or to make fraudulent requests that look like they come from other places.

It is also possible to become over-reliant on geolocation data obtained through IP addresses. There are many other ways of determining user location, such as through GPS, automated address geocoding, or desktop geolocation.

Conclusion

Being able to identify visitors' geographical location data is a powerful tool for providing a secure and enjoyable experience for your users. You can use geolocation data to prevent online fraud, serve targeted ads, localize web pages, and geoblock content.

If you're interested in getting started with an IP geolocation database, check out some of the options listed in this article. Utilizing an API like the AbstractAPI Free IP Geolocation API is a quick and easy way to start accessing geographical location data about your users.

FAQs

What is an IP Geolocation Database?

A geolocation database allows you to look up a user's physical location based on an IP address. Most geolocation APIs (both free and paid) rely on IP location databases for their information. There are free and paid databases available, and the quality of the data may differ depending on the service.

How does IP Geolocation work?

Each device connected to the internet has a unique IP that identifies it to the network and allows other machines to make and receive requests to and from that device. The unique string of bytes can be mapped to a physical location that can tell you the city, state, region, and country from which the device is accessing the internet.

What are the benefits of an IP Database?

Geolocation can be used to target ads, serve localized web pages and currency information, block content in certain regions, and prevent bad actors from certain places from engaging in fraudulent activity.

How accurate is IP Geolocation?

Geolocation done by IP will not give you a street address, phone number, person's name or any other personally identifying information. You can get latitude and longitude coordinates and learn the city, state, region, and country that the user is in.

Elizabeth (Lizzie) Shipton

Lizzie Shipton is an adept Full Stack Developer, skilled in JavaScript, React, Node.js, and GraphQL, with a talent for creating scalable, seamless web applications. Her expertise spans both frontend and backend development, ensuring innovative and efficient solutions.

Get your free
IP Geolocation
key now
See why the best developers build on Abstract
get started for free

Related Articles

Get your free
IP Geolocation
key now
4.8 from 1,863 votes
See why the best developers build on Abstract
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required